pytest-dev / pytest-dev/pytest

--strict-markers could enable the warning to cause an error

Open
#7,051 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

plugin: warnings topic: config topic: marks
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

The --strict-markers option is not really necessary given that there is a warning already always, which could be turned into an error:

https://github.com/pytest-dev/pytest/blob/760a399925ddaacc474f2406ecb1881b72a40140/src/_pytest/mark/structures.py#L340-L357

So --strict-markers could be kept, but configure the warning accordingly.

This would make it more flexible in general, e.g. when you want to disable the option in a test.

(my current workaround was to monkeypatch pytestconfig - I'd rather would have liked to use filterwarnings):

    # Register markers for `--strict-markers`.
    added_markers = pytestconfig._inicache["markers"] + [
        "funcmark",
        "prepended",
        "funcmark2",
    ]
    monkeypatch.setitem(pytestconfig._inicache, "markers", added_markers)

)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/_pytest/mark/structures.py at the linked lines and inspect how the unknown-marker warning relates to --strict-markers. Trace the warning configuration and filterwarnings behavior, then verify that the warning can be promoted to or suppressed as an error while --strict-markers remains available.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.