Skip to content

Module-level skip no longer works #1885

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

Closed
astrofrog opened this issue Aug 29, 2016 · 3 comments
Closed

Module-level skip no longer works #1885

astrofrog opened this issue Aug 29, 2016 · 3 comments

Comments

@astrofrog
Copy link

I used to make use of the ability to invoke pytest.skip to skip a whole test file (rather than having to decorate dozens of functions):

if not SOME_PACKAGE_INSTALLED:
    pytest.skip()

but am now getting errors with pytest 3.0:

Using @pytest.skip outside of a test (e.g. as a test function decorator) is not allowed. Use @pytest.mark.skip or @pytest.mark.skipif instead.

Is there a way to simply skip a whole file instead?

@The-Compiler
Copy link
Member

Are you aware of pytest.importorskip? That seems to fit your usecase nicely - instead of:

try:
    import some_package
except ImportError:
    pytest.skip()

do:

some_package = pytest.importorskip('some_package')

@nicoddemus
Copy link
Member

We have removed this ability because it was a common error to use pytest.skip as a decorator (as opposed to using pytest.mark.skip as a decorator) and skip the entire module instead of just the decorated test.

importorskip is probably the best choice if you are just checking if a package is installed like @The-Compiler said, but if you have some other condition that you would like to check as well, you can set a pytestmark global variable:

if not SOME_RUNTIME_CONDITION:
    pytestmark = pytest.mark.skip(reason='reasons')

@astrofrog
Copy link
Author

@The-Compiler @nicoddemus importorskip fits my needs, thanks! (and good to know about the other way too just in case)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants