[WIP] classmethod and class-scoped fixtures (#3778)#3781
[WIP] classmethod and class-scoped fixtures (#3778)#3781nicoddemus wants to merge 1 commit intopytest-dev:masterfrom
Conversation
| 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) |
|
|
||
|
|
||
| class Test(object): | ||
| @classmethod |
There was a problem hiding this comment.
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
setupfunction, we lose theclassmethoddecoration; we would have to get the originalsetupfunction and somehow reapply the@classmethoddecorator in order to get the class object asclswhen 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