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

skipif + parametrize not skipping tests #1296

Closed
arxanas opened this issue Dec 30, 2015 · 12 comments
Closed

skipif + parametrize not skipping tests #1296

arxanas opened this issue Dec 30, 2015 · 12 comments
Labels
topic: marks related to marks, either the general marks or builtin topic: parametrize related to @pytest.mark.parametrize

Comments

@arxanas
Copy link

arxanas commented Dec 30, 2015

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.

@nicoddemus nicoddemus added the topic: parametrize related to @pytest.mark.parametrize label Dec 30, 2015
@nicoddemus
Copy link
Member

Thanks for the report! 😄

@kdexd
Copy link

kdexd commented Dec 12, 2016

I have recently experienced this issue. It still persists in pytest 3.0.0.

@alessss
Copy link

alessss commented Jan 9, 2017

Is there any solution for the issue? Still experiencing it in pytest==3.0.5

@RonnyPfannschmidt
Copy link
Member

@alessss markers have not been fixed, this issue is not easy to resolve due to legacy

@alessss
Copy link

alessss commented Jan 9, 2017

If i use plain True in skipif decorator it works well:
@pytest.mark.skipif(True, reason="always skip")

But if there is some function, returning True or False - tests don't start.
from distutils.version import StrictVersion
from versions import get_version
@pytest.mark.skipif(StrictVersion(get_version()) < StrictVersion('1.8.0'), reason='WRONG VERSION')

Is there any workaround for this?

@The-Compiler
Copy link
Member

@alessss I don't see how that'd be possible - and if you don't also have skipif markers on parameters, this issue is totally unrelated.

@nicoddemus
Copy link
Member

For reference, #1921 discusses how to start fixing markers in general.

@scopatz
Copy link

scopatz commented Feb 12, 2017

This is a non-obvious pain point I am experiencing on v3.0.6

@RonnyPfannschmidt
Copy link
Member

@hpk42 i beleive this one breaks apart due to yet another marker transfer detail included in parametrization

@RonnyPfannschmidt RonnyPfannschmidt added the topic: marks related to marks, either the general marks or builtin label May 14, 2017
@RonnyPfannschmidt
Copy link
Member

we can fix this by landing #2522 as well

@RonnyPfannschmidt
Copy link
Member

fixed in #3317

@RonnyPfannschmidt
Copy link
Member

fixed in #3317

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: marks related to marks, either the general marks or builtin topic: parametrize related to @pytest.mark.parametrize
Projects
None yet
Development

No branches or pull requests

7 participants