Skip to content

skipif + parametrize not skipping tests #1296

Closed
@arxanas

Description

@arxanas

I have this testing code:

import pytest


def params():
    dont_skip = pytest.mark.skipif(False, reason="don't skip")
    return [dont_skip("foo"), dont_skip("bar")]


@pytest.mark.skipif(True, reason="always skip")
@pytest.mark.parametrize("param", params())
@pytest.mark.skipif(True, reason="really always skip please")
def test_foo(param):
    assert False

The expected behavior is that if any of the skipif conditions returns True, the test is skipped. The actual behavior is that the skipif condition seems to depend entirely on the value of the dont_skip parameter. For example, the following test case causes the tests to be skipped (the Trues and Falses are swapped around):

import pytest


def params():
    dont_skip = pytest.mark.skipif(True, reason="don't skip")
    return [dont_skip("foo"), dont_skip("bar")]


@pytest.mark.skipif(False, reason="always skip")
@pytest.mark.parametrize("param", params())
@pytest.mark.skipif(False, reason="really always skip please")
def test_foo(param):
    assert False

Here's the full output of the first code sample:

$ py.test test_foo.py
============================= test session starts ==============================
platform darwin -- Python 2.7.10, pytest-2.8.6.dev1, py-1.4.31, pluggy-0.3.1
rootdir: /Volumes/Home/Users/Waleed/tmp/foo, inifile: 
collected 2 items

test_foo.py FF

=================================== FAILURES ===================================
________________________________ test_foo[foo] _________________________________

param = 'foo'

    @pytest.mark.skipif(True, reason="always skip")
    @pytest.mark.parametrize("param", params())
    @pytest.mark.skipif(True, reason="really always skip please")
    def test_foo(param):
>       assert False
E       assert False

test_foo.py:13: AssertionError
________________________________ test_foo[bar] _________________________________

param = 'bar'

    @pytest.mark.skipif(True, reason="always skip")
    @pytest.mark.parametrize("param", params())
    @pytest.mark.skipif(True, reason="really always skip please")
    def test_foo(param):
>       assert False
E       assert False

test_foo.py:13: AssertionError
=========================== 2 failed in 0.01 seconds ===========================

The issue manifests under:

  • Python 3.5 + Pytest 2.8.5
  • Python 2.7.10 + Pytest 2.8.5
  • Python 2.7.10 + Pytest HEAD (0ef73ed).

I'm running OS X 10.9.5.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: marksrelated to marks, either the general marks or builtintopic: parametrizerelated to @pytest.mark.parametrize

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions