Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
"AttributeError: object has no attribute 'add_mark'" when marks clash with existing attributes #3631
When running the following code with
import pytest def assign_foo(f): f.foo = "Hi" return f @pytest.mark.foo @assign_foo def test(): pass
I get the following error:
This is on 3.6.0 with the following packages in the virtualenv (i.e. a clean install of pytest 3.6.2):
We encountered this because someone was applying
I believe this is only a problem with the legacy support and is not required for marks to work: we already apply a hypothesis mark to all
GitMate.io thinks possibly related issues are #49 (AttributeError: 'Session' object has no attribute '_setupstate'), #362 (AttributeError: 'MyOptionParser' object has no attribute 'parse_known_args'), #2162 (AttributeError: 'SubRequest' object has no attribute 'param'), #1310 (AttributeError: '_HookCaller' object has no attribute 'spec_opts'), and #1447 (AttributeError: 'OutputWriter' object has no attribute 'isatty').
What would the warning be? What should the user be doing differently in this case?
Given that the more modern mark storage mechanism means that (as far as I can tell) it's perfectly fine to have an attribute and a mark of the same name, it seems a shame to let the legacy support turn reasonable behaviour into a warning unless there's something the user can do that will avoid that.
(In the case of Hypothesis this doesn't matter because the fix for this problem was just to tell the use "Don't do that then" as we're already applying the mark, I'm just not a fan of non-actionable warnings)
I don't think that's true though, unless I'm misunderstanding the code.
The problem is occurring only in the part of the code that applies the legacy mark info, which adds an attribute to the function. The part that adds it to the