Skip to content

pytest.skip in conftest/__init__ files doesn't work as expected #12371

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

Open
MishaVyb opened this issue May 26, 2024 · 3 comments
Open

pytest.skip in conftest/__init__ files doesn't work as expected #12371

MishaVyb opened this issue May 26, 2024 · 3 comments
Labels
topic: collection related to the collection phase

Comments

@MishaVyb
Copy link

Problem description

Pytest has special mechanism to skip modules described here.

But when applying this to conftest.py (or __init__.py), this call skip entire package, not only that module. And this happened even with allow_module_level=False. For example:

# content of tests/test_package_A/confest.py
import sys
import pytest

if sys.version_info < (3, 11):
    pytest.skip("Python>=3.11 is required. ", allow_module_level=False)
Screenshot 2024-05-26 at 12 43 42

Pytest and operating system versions

pytest 8.2.1
MacOS Monterey 12.3.1 (21E258)

Expecting behaviour

1- Do not allow using pytest.skip(allow_module_level=False) in conftest.py (or __init__.py). The same, as It's not allowed for test modules. So, expected error message might be the same:

Using pytest.skip outside of a test will skip the entire module. If that's your intention, pass allow_module_level=True

2- And even more, I would suggest that another flag should be set explicitly to skip entire directory/package. For example:

pytest.skip("Python>=3.11 is required. ", allow_package_level=True)   # package level flag specified here
@RonnyPfannschmidt
Copy link
Member

I'd opt for entirely deprecatingly module level skip instead, import time ought to only allow declarative mechanisms

@MishaVyb
Copy link
Author

I'd opt for entirely deprecatingly module level skip instead, import time ought to only allow declarative mechanisms

Probably, I'd agree with you. Anyway we should report an error in that case, instead of skipping everything silently

@Zac-HD Zac-HD added the topic: collection related to the collection phase label May 27, 2024
@MishaVyb
Copy link
Author

MishaVyb commented Jun 9, 2024

Is anyone interesting in it to open a PR? If no other who wish to, I would like to do it. It doesn't look difficult

But we need to consider, what behaviour should be in that case? Some verbose error message similar to this?

Using pytest.skip at top level of conftest.py/init.py files is not allowed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: collection related to the collection phase
Projects
None yet
Development

No branches or pull requests

3 participants