pytest: Emit warnings on use of unknown marks

One of the most common problems I see, and help debug, is typos in @pytest.mark.whatever decorators. Just recently we’ve had #4639 and #4814, and I’ve read three sets of unrelated docs in the last week that explicitly point out the spelling of mark.parametrize (not parameterize!).

The --strict argument helps, but is clearly insufficient by default. On the other hand, it can’t be an error until a major version bump.

Happily, there is a standard middle ground: warnings! I therefore propose to emit a warning every time an unknown name is used as an attribute of pytest.mark. The message should include how to register the mark, why unregistered marks are problematic, and note that this warning may become an error in a future version of pytest.

Unless there are major objections to this plan, I’ll try for an implementation over the weekend.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 2
  • Comments: 21 (15 by maintainers)

Commits related to this issue

Most upvoted comments

@1313e

You mean pytest_pep8 does register the pep8 mark and pytest still complains about it being unknown?

Correct.

Took a quick look and that does not seem to be the case:

https://bitbucket.org/pytest-dev/pytest-pep8/src/44ddb3739f0f892fc0029d5d809496ec5ef24f28/pytest_pep8.py#lines-12:21

The pep8 mark should be registered like shown here.