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
- multiple choice: 129
- true false: 123
- select blank: 53
- code fill: 11
- short answer: 10
- match pairs: 5
- order: 4
- multi select: 4
- categorize: 2
- command output: 1
What's covered
- What pytest Is and Why It Replaced unittest
- Installing pytest and Running Your First Test
- Test Discovery Conventions
- Writing Assertions with Plain assert
- Assertion Rewriting and Failure Messages
- Fixtures Fundamentals
- Fixture Scopes
- conftest.py and Fixture Sharing
- Built-in Fixtures: tmp_path, capsys, monkeypatch
- Yield Fixtures and Teardown
- Parametrizing Tests
- Parametrizing Fixtures
- Marking Tests: skip, skipif, xfail
- Custom Markers and Registration
- Testing Exceptions with pytest.raises
- Testing Warnings with pytest.warns
- Mocking with pytest-mock
- Measuring Coverage with pytest-cov
- Running Tests in Parallel with pytest-xdist
- Configuring pytest: pyproject.toml and ini Options
- Organizing a Test Suite: src Layout
- Debugging Failing Tests: -v, -x, -k, --pdb
- Common pytest Anti-Patterns and Best Practices
Example cards
multiple choice
pytest tests are written as:
multiple choice
pytest checks results using:
Latest: Initial release — 23 decks, each pack with a preview card teaching the concept before its graded main card and practice cards.