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

marker transfer incompatible with inheritance #535

Closed
pytestbot opened this issue Jun 30, 2014 · 3 comments
Closed

marker transfer incompatible with inheritance #535

pytestbot opened this issue Jun 30, 2014 · 3 comments
Labels
topic: marks related to marks, either the general marks or builtin type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

Originally reported by: Ronny Pfannschmidt (BitBucket: RonnyPfannschmidt, GitHub: RonnyPfannschmidt)


when a method is inherited, markers will trasnfer from the subclass to the superclass

#!python


import pytest

class TestAClass(object):

    def test_something(self):
        assert True

@pytest.mark.skipif("True")
class TestBClass(TestAClass):
    pass

class TestCClass(TestAClass):
    pass

will skip in TestCClass (given by tradej on irc)

im not yet sure if there is a clear backward-compatible way to solve this


@pytestbot
Copy link
Contributor Author

Original comment by BitBucket: tgoodlet, GitHub: tgoodlet:


This is particularly painful with the pytest.mark.usefixtures decorator when sibling classes require mutually exclusive dependencies.
I was wondering why would fixing this problem affect backwards compat? Isn't this just simply incorrect?
What use case would leverage this?

@pytestbot
Copy link
Contributor Author

Original comment by BitBucket: tgoodlet, GitHub: tgoodlet:


After a decent adventure into the source I've found the guilty method to be _pytest.python.PyCollector.collect() for Instance nodes:

https://bitbucket.org/hpk42/pytest/src/1189057a5a525222c98ceaf8d91a3e9614316409/_pytest/python.py?at=default#cl-317

The test function which is actually passed to self.makeitem(name, obj) is that from the parent class definition (i.e. self.obj.__class__.__dict__) and not the current instance (i.e. self.obj).
So the callable is actually the class function definition not the unbound class method or current instance method.
Addtionally, there is an underlying check in the _pytest.python.py: pytest_pycollect_makeitem hook namely, inspect.isfunction(obj) here:
https://bitbucket.org/hpk42/pytest/src/1189057a5a525222c98ceaf8d91a3e9614316409/_pytest/python.py?at=default#cl-227

This prevents modifcation of this method to simply call makeitem on the instance method...
I assume there is/was a good reason for this?
Can anyone comment on why this restriction is in place?
Also what was the original motivation behind not using the instance method directly?

@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 type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

2 participants