Built-in marks
Having learned the basics of marks and how to use them, let's now take a look at some built-in pytest marks. This is not an exhaustive list of all built-in marks, but the more commonly used ones. Also, keep in mind that many plugins introduce other marks as well.
@pytest.mark.skipif
You might have tests that should not be executed unless some condition is met. For example, some tests might depend on certain libraries that are not always installed, or a local database that might not be online, or are executed only on certain platforms.
Pytest provides a built-in mark, skipif
, that can be used to skip tests based on specific conditions. Skipped tests are not executed if the condition is true, and are not counted towards test suite failures.
For example, you can use the skipif
mark to always skip a test when executing on Windows:
import sys import pytest @pytest.mark.skipif( sys.platform.startswith("win"), reason="fork not available on Windows", ) def test_spawn_server_using_fork...