Course · Training · Workshop

Testing with pytest

Three-day deep-dive into the pytest framework, to simplify software testing: Writing your first test, using fixtures, mocking, and even writing your own plugins.

Automated testing is one of the most important ingredients for quality code - yet it is often neglected or seen as a tedious chore. With pytest, things magically get easier: Tests can be written in Python in a very flexible and simple way. The framework can easily be adopted to custom workflows and preferences -- even to test non-Python code.

What participants say

These customers booked courses in the same topic cluster.More customers →

Content

This course provides an introduction to the pytest framework with numerous exercises and examples. We start with the basics and work our way through the various features that pytest offers. We don’t stop there, but also cover intermediate and advanced topics such as fixtures, mocking, and writing custom plugins.

In this course, one of the main developers of pytest will answer the following questions - and many more:

  • Introduction and Terminology: Why write tests? Why pytest? What types of tests do exist?
  • First Steps and Assertions: How do I write my first test? How do I verify that my code does what it should?
  • Configuration and CLI: How do I run tests and how can I influence the behavior of pytest?
  • Organizing Tests: How do I structure my tests? How do I categorize them with markers?
  • Parameterization: How can I run the same test with different inputs and outputs?
  • Fixtures: How can I prepare and reuse test data or objects? How do I avoid code duplication for setup and teardown code? What functionality does pytest provide in the form of built-in fixtures? How can I use caching and parameterization of fixtures?
  • Migration: How do I migrate from another Python test framework to pytest?
  • Mocking: How do I deal with tightly coupled components or external dependencies? What tools and alternatives are available for mocking and patching?
  • Hypothesis: How can I increase test coverage with generative tests? How do I write custom strategies? What are the limits of property-based testing?
  • Plugin Tour: What can pytest plugins do? What does the ecosystem around pytest look like?
  • Custom Plugins: How can I customize pytest to my needs? How do I implement custom plugin hooks? How do I share and publish a plugin?

The actual course content may differ from the above depending on the trainer, delivery, duration and the composition of participants.

Request this course in-house

By submitting you accept our Privacy Policy.

Request a public date

No suitable public date? Register without obligation — once there is enough interest we schedule a new public date and let you know first.

Number of participants (approx.)

More than 3 participants? Best to request a dedicated in-house date directly.

By submitting you accept our Privacy Policy.

More about pytest

pytest is a powerful Python testing framework characterized by its simple syntax and high extensibility. It supports both simple unit tests and complex functional tests, and provides a comprehensive plugin system.

Further resources:

History

pytest was originally developed by Holger Krekel and released in 2004 as 'py.test'. It emerged from the need to create a simpler and more flexible testing framework than Python's built-in unittest, which was inspired by JUnit.

Development was significantly driven by the Python testing community, with important contributions from Ronny Pfannschmidt and Bruno Oliveira. A significant milestone was the introduction of the fixture system in version 2.0, which revolutionized how test environments are set up.

Today, pytest is the most widely used testing framework in the Python world and is used by projects like Mozilla, Dropbox, and Kubernetes. It has not only changed how Python developers write tests but also set new standards for test frameworks in other languages. The integration with tools like Hypothesis for property-based testing and broad plugin support make it an indispensable tool in modern Python development.