-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
[WIP] classmethod and class-scoped fixtures (#3778) #3781
Conversation
@@ -667,7 +667,9 @@ def copy_example(self, name=None): | |||
example_path.copy(result) | |||
return result | |||
else: | |||
raise LookupError("example is not found as a file or directory") | |||
raise LookupError( | |||
"example {} is not found as a file or directory".format(example_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should use !r
|
||
|
||
class Test(object): | ||
@classmethod |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the order in-correctness i was talking about in #3780 - we structurally have to loose something as long as we wrap
I gave this another go and I can't get it to work: Even when I work around this by obtaining the I'm nearly giving up here. I see two solutions:
What do you think @RonnyPfannschmidt? Because it worked mostly by accident and there's an easy workaround, I'm leaning towards 2). |
class methods can be stroked via the descriptor protocol to return the actual function
|
so I'm leaning towards 3 - using the descriptor protocol (and encapsulating this bugger into something) |
Thanks for the code. I did obtain the underlying function with my testing earlier but ran in other errors in other parts, but I will give this another go then! |
I gave this another go but still no success. 😞 In this example: class Test:
@classmethod
@pytest.fixture(scope='class', autouse=True)
def setup(cls):
... What happens is:
When we get to the point of creating the The function is obtained using At this point we have these function layers:
And here lies the problem as I see it: as we unwrap Would you mind giving a go at this branch yourself? I'm nearly giving up, I'm afraid. |
at earliest i can try next week |
Sure, sounds good, thanks! |
@RonnyPfannschmidt still want to try to fix this? I think this has very little use as we haven't seen more reports about this problem other than in #3778. I'm inclined to just close this and keep the existing behavior. |
Closing for the reasons stated in #3778 (comment). |
Unfortunately I could not come up with a fix here.
The issue is that the fixture is declared as:
When we "unwrap" the fixture to get to the underlying
setup
function, we lose theclassmethod
decoration; we would have to get the originalsetup
function and somehow reapply the@classmethod
decorator in order to get the class object ascls
when we call the function later. I don't see any way to do this in a general manner.After thinking about this issue I'm afraid the conclusion is that we have to pull back the warning about calling fixture functions directly: its intention was good but this has caused many more problems than we expected to be worth the trouble at this point.
xref: #3778