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

Comments

Projects
2 participants
@pytestbot
Copy link

pytestbot commented Jun 30, 2014

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

This comment has been minimized.

Copy link
Author

pytestbot commented Jul 24, 2014

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

This comment has been minimized.

Copy link
Author

pytestbot commented Jul 28, 2014

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

This comment has been minimized.

Copy link
Member

RonnyPfannschmidt commented Apr 10, 2018

fixed in #3317

@RonnyPfannschmidt RonnyPfannschmidt moved this from in progress to done in resolve the mark fallout Apr 10, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.