Registering Markers to Avoid Marker Typos

Custom markers, as discussed in Marking Test Functions, are great for allowing you to mark a subset of tests to run with a specific marker. However, it’s too easy to misspell a marker and end up having some tests marked with @pytest.mark.smoke and some marked with @pytest.mark.somke. By default, this isn’t an error. pytest just thinks you created two markers. This can be fixed, however, by registering markers in pytest.ini, like this:

 [pytest]
 markers =
 smoke:​ ​Run​ ​the​ ​smoke​ ​test​ ​functions​ ​for​ ​tasks​ ​project
 get:​ ​Run​ ​the​ ​test​ ​functions​ ​that​ ​test​ ​tasks.get()

With these markers registered, you can now also see them with pytest --markers with their descriptions:

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.