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

3.0 fails with importorskip on module level #1822

Closed
The-Compiler opened this issue Aug 19, 2016 · 2 comments
Closed

3.0 fails with importorskip on module level #1822

The-Compiler opened this issue Aug 19, 2016 · 2 comments
Labels
type: regression indicates a problem that was introduced in a release which was working previously

Comments

@The-Compiler
Copy link
Member

The-Compiler commented Aug 19, 2016

Because 3.0 disallows pytest.skip at module-level, using pytest.importorskip fails:

import pytest
foobarbaz = pytest.importorskip("foobarbaz")

def test_foo():
    pass

with 2.9.2:

========================== test session starts ===========================
platform linux -- Python 3.5.2, pytest-2.9.2, py-1.4.31, pluggy-0.3.1
rootdir: /home/florian, inifile: 
plugins: mock-1.2
collected 0 items / 1 skipped 

with 3.0.0:

========================== test session starts ===========================
platform linux -- Python 3.5.2, pytest-3.0.0, py-1.4.31, pluggy-0.3.1
rootdir: /home/florian, inifile: 
plugins: hypothesis-2.0.0, catchlog-1.2.1
collected 0 items / 1 errors 

================================= ERRORS =================================
_________________________ ERROR collecting x.py __________________________
Using @pytest.skip outside a test (e.g. as a test function decorator) is not allowed. Use @pytest.mark.skip or @pytest.mark.skipif instead.
!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!
======================== 1 error in 0.13 seconds =========================

This was pointed out in #pylib by @jaraco as setuptools did run into it: test_msvc.py

I think this is a valid pattern (and the error message is confusing) - maybe pytest.skip should have some allow_module_level argument and importorskip should use it (without me actually having looked at the code)?

cc @omarkohl

@The-Compiler The-Compiler added the type: regression indicates a problem that was introduced in a release which was working previously label Aug 19, 2016
@nicoddemus
Copy link
Member

Probably what's happening is that importorskip uses pytest.skip directly... without looking at the code I think the easiest solution is for importorskip to raise SkipError (or something) directly instead.

@nicoddemus
Copy link
Member

@The-Compiler went with your suggestion, going to open a PR in a few minutes.

nicoddemus added a commit to nicoddemus/pytest that referenced this issue Aug 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression indicates a problem that was introduced in a release which was working previously
Projects
None yet
Development

No branches or pull requests

2 participants