pytest markers label tests and can be registered to avoid unknown-mark warnings
Answer: You can mark test functions so you can select or deselect them, for example with -m. You can register new markers programmatically in a pytest_configure hook. Registered marks appear in pytest's help text and do not emit warnings.
Unknown marks
Unregistered marks avoid silently doing something surprising due to mistyped names. Unregistered marks applied with @pytest.mark.name_of_the_mark will always emit a warning. When the strict_markers configuration option is set, any unknown marks applied with that decorator will trigger an error. You can enforce this validation by setting strict_markers in your configuration, or with addopts = ["--strict-markers"].
Note that everything past the : after the mark name is an optional description.
See also
Claims
- id: C1 claim: You can register markers in a pytest_configure hook. source: S1 evidence: "you can register new markers programmatically in a"
- id: C2 claim: Unregistered marks emit a warning to catch mistyped names. source: S2 evidence: "will always emit a warning in order to avoid silently doing something"
- id: C3 claim: strict_markers turns an unknown mark into an error. source: S2 evidence: "any unknown marks applied"
- id: C4 claim: Text past the colon after a mark name is an optional description. source: S2 evidence: "everything past the `
:` after the mark name is an optional description."
Sources
- [S1] How to mark test functions. pytest docs. https://docs.pytest.org/en/stable/how-to/mark.html . License: MIT. Accessed 2026-11-16.
- [S2] How to mark test functions (pytest source docs). pytest-dev/pytest (GitHub). https://github.com/pytest-dev/pytest/blob/main/doc/en/how-to/mark.rst . License: MIT. Accessed 2026-11-16.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: pytest docs, How to mark test functions, MIT (https://raw.githubusercontent.com/pytest-dev/pytest/main/LICENSE); pytest-dev/pytest (GitHub), How to mark test functions (pytest source docs), MIT (https://raw.githubusercontent.com/pytest-dev/pytest/main/LICENSE). Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: pytest docs, How to mark test functions, MIT (https://raw.githubusercontent.com/pytest-dev/pytest/main/LICENSE); pytest-dev/pytest (GitHub), How to mark test functions (pytest source docs), MIT (https://raw.githubusercontent.com/pytest-dev/pytest/main/LICENSE).
Cite this
iinventedlight. 2026. "pytest markers label tests and can be registered to avoid unknown-mark warnings." iinventedlight Library, iil:note:d9dm81zp, version of 2026-11-16. https://iinventedlight.com/library/notes/pytest-markers/. License: CC-BY-4.0.
@misc{iil_note_d9dm81zp,
author = {{iinventedlight}},
title = {{pytest markers label tests and can be registered to avoid unknown-mark warnings}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-16},
url = {https://iinventedlight.com/library/notes/pytest-markers/},
note = {Permanent ID iil:note:d9dm81zp. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/pytest-markers.md.