Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also emit PytestUnknownMarkWarning for unknown marks given in -m #12166

Closed
The-Compiler opened this issue Mar 28, 2024 · 3 comments
Closed

Also emit PytestUnknownMarkWarning for unknown marks given in -m #12166

The-Compiler opened this issue Mar 28, 2024 · 3 comments
Labels
topic: marks related to marks, either the general marks or builtin

Comments

@The-Compiler
Copy link
Member

If we use @pytest.mark with a mark that does not exist, pytest warns about it:

import pytest

@pytest.mark.one
def test_one():
    pass

results in:

  .../test_x.py:3: PytestUnknownMarkWarning: Unknown pytest.mark.one - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/how-to/mark.html
    @pytest.mark.one

This is to avoid silent failures, e.g. a test being marked onne and then never being executed.


However, a similar issue exists with -m too! If, with the code above, we use pytest -m onne, that results in:

============================= test session starts ==============================
collected 1 item / 1 deselected / 0 selected                                   

============================ 1 deselected in 0.43s =============================

Thanks to exit code 5 (ExitCode.NO_TESTS_COLLECTED), this can still be spotted, more or less. However, when using e.g. pytest -m "slow or onne", it's not trivially visible anymore that a typo was made (assuming that some tests run due to the slow mark, of course).

Is there a good reason to not validate all marks passed into -m against the list of registered marks as well? Have we had an issue about this before? This gets pointed out every once in a while by participants in my pytest trainings, and I feel like I must have reported it before, but I can't seem to find anything.

@The-Compiler The-Compiler added the topic: marks related to marks, either the general marks or builtin label Mar 28, 2024
@poulami-sau
Copy link
Contributor

Hello! If I'm understanding correctly, I think you reported this same issue in #10514? I am interested in working on this issue, but I'm having a hard time trying to simulate the conditions, and would appreciate some guidance on this!

@The-Compiler
Copy link
Member Author

Hah, so my memory didn't fail me, and I just didn't find it 🙈. Thanks, closing this one as a duplicate then. I'll answer the rest over there.

@The-Compiler
Copy link
Member Author

Duplicate of #10514

@The-Compiler The-Compiler marked this as a duplicate of #10514 Apr 2, 2024
@The-Compiler The-Compiler closed this as not planned Won't fix, can't repro, duplicate, stale Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: marks related to marks, either the general marks or builtin
Projects
None yet
Development

No branches or pull requests

2 participants