February 2022
Intermediate to advanced
274 pages
6h 28m
English
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 ...