Skip to content

pytest.skip will skip entire files when used as a decorator #607

Closed
@pytestbot

Description

@pytestbot

Originally reported by: Bryce Lampe (BitBucket: blampe, GitHub: blampe)


I've seen several people assume that @pytest.skip can be used in place of @pytest.mark.skipif(True, reason="foo"). It seems like a reasonable convenience and it seems to work. However, this is actually quite dangerous because it has the unexpected side-effect of skipping every test in the file:

$ cat test.py
import pytest

@pytest.skip
def test_1():
    print 1

def test_2():
    print 2

def test_3():
    print 3

Expected behavior:

$ py.test test.py -v
============================= test session starts ==============================
platform darwin -- Python 2.7.8 -- py-1.4.25 -- pytest-2.6.3 -- /Users/blampe/env/bin/python2.7
collected 2 items

test.py::test_2 PASSED
test.py::test_3 PASSED

=========================== 2 passed in 0.01 seconds ===========================

Actual behavior:

$ py.test test.py -v
============================= test session starts ==============================
platform darwin -- Python 2.7.8 -- py-1.4.25 -- pytest-2.6.3
collected 0 items / 1 skipped

========================== 1 skipped in 0.00 seconds ==========================

Note that this is reporting the wrong number of skipped tests, so this definitely seems unintentional.


Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueeasy issue that is friendly to new contributortype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions