Running a Subset of Tests
In the previous section, we used test classes to be able to run a subset of tests. Running just a small batch of tests is handy while debugging or if you want to limit the tests to a specific section of the code base you are working on at the time.
pytest allows you to run a subset of tests in several ways:
Subset | Syntax |
|---|---|
Single test method | pytest path/test_module.py::TestClass::test_method |
All tests in a class | pytest path/test_module.py::TestClass |
Single test function | pytest path/test_module.py::test_function |
All tests in a module | pytest path/test_module.py |
All tests in a directory | pytest path |
Tests matching a name pattern | pytest -k pattern |
Tests by marker | Covered in Chapter 6, Markers. |
We’ve used everything but pattern and marker ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access