-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Odd/incorrect behaviour when marking a test superclass #842
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
Comments
the real problem is a bug in marker transfer from test classes to functions, i recall we have a open bug about that topic |
There might be an other issue in function transfer, but as far as I can see the application of markers themselves is already problematic (and I tried to outline how), I don't see how changes happening after that would fix it, the function transfer is going to transfer an incorrect set of markers either way. |
true, i missed that detail due to thinking of the old issue thanks for bringing it up in a direct form again |
Been there, done that. 😄
Actually fixtures use another mechanism than markers. Thanks for the report, I'll take a look into this. |
#725? |
See pytest-dev/pytest#842 for relevant pytest issue.
See pytest-dev/pytest#842 for relevant pytest issue.
Currently looking into pytest to port over a unittest-based test system with quite a bunch of customisations, we have a number of base "test superclass" for opt-in capabilities and setup/teardown code reuse.
While in the future we'll probably phase them out for regular fixtures & markers, right now I'm trying to "softly" add pytest and these superclasses seemed like a nice seam for a few default markers, fixtures and the like, and then things started breaking down completely: class-level markers (and fixtures since I understand fixtures are enabled through markers? I may be mistaken) are shared between classes rather than only copied/shared from superclass to subclass.
More precisely, if a class has a marker, any marker apparently set on a subclass will actually be set on the superclass (and on all "sibling" subclasses"):
Selecting using
-m b
, one would expect onlytest_foo
would be collected…Digging in the code, the problem is in
MarkDecorator
:so if
func
is a class and it has apytestmark
attribute which is already a list then append the newMarkDecorator
to the list. This is problematic if the existing pytestmark comes from a superclass rather than being set on the current class.I see a number of other possible problems with the code in case
pytestmark
is set explicitly (rather than implicitly via mark decorators)These seem like somewhat less problematic issue though as they're explicit and follow fairly normal Python inheritance concerns. The oddity with MarkDecorator is it's completely implicit, and seems desirable in no situation whatsoever.
Also why look for
__bases__
instead of seeing if func is an instance of type or types.ClassType?The text was updated successfully, but these errors were encountered: