Marking Files, Classes, and Parameters

With the tests in test_start.py, we added @pytest.mark.<marker_name> decorators to test functions. We can also add markers to entire files or classes to mark multiple tests, or zoom in to parametrized tests and mark individual parametrizations. We can even put multiple markers on a single test. How fun. We’ll use all the mentioned marker types with test_finish.py.

Let’s start with file-level markers:

 import​ ​pytest
 from​ ​cards​ ​import​ Card, InvalidCardId
 
 
 pytestmark = pytest.mark.finish

If pytest sees a pytestmark attribute in a test module, it will apply the marker(s) to all the tests in that module. If you want to apply more than one marker to the file, you can ...

Get Python Testing with pytest now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.