That structuring of test code actually works quite well and is sufficient for many projects. However, pytest also allows us to group tests with classes, marker, module and package.
Grouping Tests with directory, modules, marker and Classes.
Running a Subset of Tests
All tests in a directory
All tests in a module
Single test function
All tests in a class
Single test method
Tests matching a name pattern
Marker
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
Classes can be used to group tests.
Running small subsets of tests is handy while debugging, and pytest allows you to run a small batch of tests in many ways.