Learn pytest basics for Python testing. Install pytest, write assertions, run test functions, and interpret output from the pytest runner step by step.
Tutorial series
Python Testing
6 tutorials — follow in order for the best learning path.
- pytest Basics: Writing Your First Python Tests with pytest
- pytest Fixtures and Parametrize
pytest fixtures share setup across tests. Parametrize runs the same test against multiple inputs. Covers scopes, autouse, and combining.
- Mocking Python: Test Doubles, patch, and MonkeyPatch in pytest
Learn mocking Python tests with unittest.mock, patch, and MonkeyPatch. Replace slow APIs, databases, and external services with controlled test doubles.
- Testing Async Code with pytest
Test async functions and coroutines with pytest-asyncio. Use async fixtures, patch async code, and handle event loop scope correctly.
- Property-Based Testing with Hypothesis
Write tests that verify behaviour across hundreds of automatically generated inputs, catching edge cases that example-based testing misses. Use Hypothesis to...
- Code Coverage and Mutation Testing
Measure code coverage with Coverage.py, then use mutation testing to verify your tests actually catch bugs.