The pytest tool presents a rapid and simple way to write tests for your Python code. This training gives an introduction with exercises to some distinguishing features. We'll also examine how to run existing non-pytest test suites and discuss migration strategies. Various plugins which extend pytest's functionality even further will be introduced.
This is the planned outline:
(30 minutes) pytest feature walkthrough:
- Automatic test discovery
- Assertions without boilerplate via the assert statement
- Configuration and commandline options
- Marking and skipping tests
- Data-driven tests via parametrization
(30 minutes) pytest fixture mechanism:
- Setup and teardown via dependency injection
- Declaring and using function/module/session scoped fixtures
- Using fixtures from fixture functions
- Parametrizing fixtures
- Looking at useful built-in fixtures (managing temporary files, patching, output capturing)
(15 minutes): Running existing unittest suites with pytest:
- Discussing advantages and limitations
- Strategies for migrating to pytest
(15 minutes): Useful third-party plugins:
- Coverage integration
- Property-based testing (automated testcase generation) via Hypothesis
Basic Python OOP knowledge (e.g. what a class/instance is) is required.
Florian Bruhin ("The Compiler") is a long-time contributor and maintainer of both the pytest framework and various plugins. In 2013, he started the qutebrowser project, a keyboard-focused web browser based on Python and Qt. In 2015, he discovered pytest - since then, he has given talks and conducted workshops about pytest at various conferences and companies.