← All notes

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

Sources

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

Permanent ID: iil:note:d9dm81zp

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.},
}

Markdown

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.