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

Class decorator marks multiple classes #2404

Closed
tetianakh opened this issue May 12, 2017 · 1 comment
Closed

Class decorator marks multiple classes #2404

tetianakh opened this issue May 12, 2017 · 1 comment

Comments

@tetianakh
Copy link

If test classes inherit from a base class, marking one of them as xfail marks the next classes also.
Here's a minimal example:

import pytest

class FooCase:
    def test_foo(self):
        assert True

class TestFoo(FooCase):
    pass

@pytest.mark.xfail()
class TestBar(FooCase):
    pass

class TestMoreFoo(FooCase):
    pass

When running this, the 2nd test is XPASS (as expected), and the third one is XPASS too (unexpectedly):

(.venv) ➜  pytest-fail pytest -vv
=========================== test session starts===============================
platform linux -- Python 3.5.2, pytest-3.0.7, py-1.4.33, pluggy-0.4.0 -- /home/tetiana/stuff/pytest-fail/.venv/bin/python3.5
cachedir: .cache
rootdir: /home/tetiana/stuff/pytest-fail, inifile:
collected 3 items 

test_poc.py::TestFoo::test_foo PASSED
test_poc.py::TestBar::test_foo XPASS
test_poc.py::TestMoreFoo::test_foo XPASS

Environment: Ubuntu 16.04, Python 3.5.2; pip freeze output:

pkg-resources==0.0.0
py==1.4.33
pytest==3.0.7

In my project, I have a suite of functional tests, where the tests are the same, but setup fixtures are different. So the tests are defined in a base class, and there's a subclass for each kind of setup.
Sadly, I can't mark a subclass as xfail, because then classes which are collected later (even in different files!) get marked as xfail.

Any help is much appreciated.

If someone could point me to the part of the source code where the problem might be, I'll gladly look into it.

@The-Compiler
Copy link
Member

See #568, #1670.

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

2 participants