pyguides

Tutorial series

Python Testing

6 tutorials — follow in order for the best learning path.

  1. pytest Basics: Writing Your First Python Tests with pytest

    Learn pytest basics for Python testing. Install pytest, write assertions, run test functions, and interpret output from the pytest runner step by step.

  2. pytest Fixtures and Parametrize

    pytest fixtures share setup across tests. Parametrize runs the same test against multiple inputs. Covers scopes, autouse, and combining.

  3. 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.

  4. 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.

  5. 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...

  6. Code Coverage and Mutation Testing

    Measure code coverage with Coverage.py, then use mutation testing to verify your tests actually catch bugs.