@pytest.mark.skip(reason="Not ready") applied to test_feature()?import pytest @pytest.mark.skip(reason="Not ready") def test_feature(): assert 1 == 1 def test_other(): assert 2 == 2
The @pytest.mark.skip marker tells pytest to skip the test. The test is not run, so it neither passes nor fails. The other test runs and passes normally. The test report shows one passed and one skipped test.
slow in pytest?import pytest def test_example(): pass # Assume test_example is marked with @pytest.mark.slow
pytest stores markers in a list called pytestmark attached to the test function. Each marker is an object with a name attribute. To check if a marker named 'slow' is present, you must check if any marker's name equals 'slow'.
integration?# content of pytest.ini [pytest] markers = integration: mark test as integration test # test_sample.py import pytest @pytest.mark.integration def test_api(): assert True
The test function test_api has an extra space before its definition line, causing an IndentationError. This prevents pytest from running the test and using the marker properly.
database?-m option filters tests by marker expression.The -m option in pytest runs tests that match the given marker expression. Using pytest -m database runs only tests marked with @pytest.mark.database.
pytest.ini file under the markers section?Declaring custom markers in pytest.ini under the markers section prevents pytest from showing warnings about unknown markers. It also serves as documentation for other developers about the purpose of each marker.