Testing with pytest 

Course & Training

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.

In-House Course:

We are happy to conduct tailored courses for your team - on-site, remotely or in our course rooms.

Request In-House Course

   

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?


Disclaimer: The actual course content may vary from the above, depending on the trainer, implementation, duration and constellation of participants.

Whether we call it training, course, workshop or seminar, we want to pick up participants at their point and equip them with the necessary practical knowledge so that they can apply the technology directly after the training and deepen it independently.

Goal:

After this course, participants will be familiar with a new, powerful tool for daily software development. Writing tests should stop feeling like a tedious chore and turn into a pleasant and productive activity. Even advanced topics and pytest features such as fixtures, mocking, and plugins will no longer be a mystery after this course.


Form:

The course is designed to be interactive and consists of a mix of lectures, examples from various projects, live coding, and exercises. Participants can directly put what they have learned into practice and write their own tests.


Target Audience:

The course is designed to be suitable for both beginners and advanced users. All developers who want to improve their software quality and simplify their tests are welcome in this course.


Requirements:

Basic Python knowledge such as writing your own functions and classes is required. We will primarely use pytest as a command-line tool, so a basic understanding of the command line is helpful.


Preparation:

Every participant will receive a questionnaire and a preparation checklist after registration.

A supported Python version and development environment of choice (e.g. PyCharm or VS Code) should be set up on your own laptop. The packages pytest and hypothesis are required, which can e.g. be installed via pip.

Request In-House Course:

In-House Kurs Anfragen

Waitinglist for public course:

Sign up for the waiting list for more public course dates. Once we have enough people on the waiting list, we will determine a date that suits everyone as much as possible and schedule a new session. If you want to participate directly with two colleagues, we can even plan a public course specifically for you.

Waiting List Request

(If you already have 3 or more participants, we will discuss your preferred date directly with you and announce the course.)

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.




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.





Share by: