← All courses

Testing with pytest

The pytest testing framework in depth: fixtures, parametrization, mocking, coverage, and configuration. Assumes you already know Python (see this library's python-basics course) and general testing vocabulary (see testing-in-software-engineering) — this course is about the pytest tool itself.

pytestpythontestingqaintermediate
23decks
44main cards
298practice cards
0%with images
v1.0.0version

Card type mix

What's covered

  1. What pytest Is and Why It Replaced unittest
  2. Installing pytest and Running Your First Test
  3. Test Discovery Conventions
  4. Writing Assertions with Plain assert
  5. Assertion Rewriting and Failure Messages
  6. Fixtures Fundamentals
  7. Fixture Scopes
  8. conftest.py and Fixture Sharing
  9. Built-in Fixtures: tmp_path, capsys, monkeypatch
  10. Yield Fixtures and Teardown
  11. Parametrizing Tests
  12. Parametrizing Fixtures
  13. Marking Tests: skip, skipif, xfail
  14. Custom Markers and Registration
  15. Testing Exceptions with pytest.raises
  16. Testing Warnings with pytest.warns
  17. Mocking with pytest-mock
  18. Measuring Coverage with pytest-cov
  19. Running Tests in Parallel with pytest-xdist
  20. Configuring pytest: pyproject.toml and ini Options
  21. Organizing a Test Suite: src Layout
  22. Debugging Failing Tests: -v, -x, -k, --pdb
  23. Common pytest Anti-Patterns and Best Practices

Example cards

multiple choice

pytest tests are written as:

  • Functions
  • Classes only
  • Modules
multiple choice

pytest checks results using:

  • assert
  • assertEqual
  • checkThat

Latest: Initial release — 23 decks, each pack with a preview card teaching the concept before its graded main card and practice cards.