pytest "Unknown pytest.mark" Warning Failing CI as an Error
You used a custom marker pytest doesn’t know about. With --strict-markers or a warnings-as-errors filter, that warning becomes a hard failure in CI even though it passes locally.
What this error means
CI fails with X not found in markers configuration option or a PytestUnknownMarkWarning escalated to an error. The same tests pass locally where strict mode is off.
pytest output
tests/test_slow.py:8: PytestUnknownMarkWarning: Unknown pytest.mark.slow -
is this a typo? You can register custom marks ...
# with --strict-markers:
'slow' not found in 'markers' configuration optionCommon causes
Custom marker not registered
Markers like @pytest.mark.slow must be declared in config. Unregistered, they warn - and under strict mode, fail.
Strict markers or warnings-as-errors in CI
--strict-markers or filterwarnings = error (common in CI configs) turns the otherwise-harmless warning into a failing run.
How to fix it
Register your markers
Declare every custom marker so pytest recognizes it.
pyproject.toml
[tool.pytest.ini_options]
markers = [
"slow: marks tests as slow",
"integration: requires external services",
]Fix typos or scope the warning filter
- Check the marker name isn’t a typo (
@pytest.mark.slwo). - Keep
--strict-markerson - it catches typos - and just register valid markers. - If a third-party marker triggers it, add a targeted
filterwarningsignore rather than disabling strict mode globally.
How to prevent it
- Register all custom markers in
markersconfig. - Keep
--strict-markersenabled to catch typos early. - Scope warning filters narrowly instead of turning strict mode off.
Related guides
pytest Exit Codes in CI - What 0–5 Mean and How to Handle ThemUnderstand pytest exit codes 0–5 in CI - passed, failures, interrupted, internal error, usage error, and no-t…
pytest "fixture 'X' not found" - Fix Missing Fixtures in CIFix pytest "fixture 'X' not found" in CI - a fixture defined in the wrong place, a missing conftest.py, or a…