Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(fixtures): Replace fixture represenation with a class #12473
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
(fixtures): Replace fixture represenation with a class #12473
Changes from all commits
41c7c2c
cee9044
004f29f
224595a
8666dfb
b724030
4552e06
1efc230
b6f87a3
bc69c19
da5e8e9
ec7f7b1
f61c23c
144befb
e556218
a48b2a0
c7d8339
6ba2370
3bc5ad1
04a0cde
9822c94
786aec5
afe72f6
3b66f72
149cc30
eb3943c
2891be5
1734722
d749473
fa2f2b5
1b5b4c7
6ee850a
131e306
f062ff6
7f1b8d3
fb4ce59
3f22fe5
98ea2f5
72269d8
d625874
2f1a17e
d909768
56899f6
ad3f0fa
845d50e
a6d0998
0bb4f14
68a66b5
a160a6a
b1de16a
3ba7108
475deb1
723a8f3
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
The previous code used
functools.wraps
, while the new code does the wrapping "manually". Butfunctools.wraps
/functools.update_wrapper
does some stuff like copy__doc__
and such. Are we losing that?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.
Yes unfortunately the new result is this object instead of a wrapped function. I was not aware of this thanks for noticing it. Since the methods that are copied are not a lot shall I just assign them just like we do with
__name__
?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.
I think the best thing would be to use
functools.update_wrapper
inFixtureFunctionDefinition.__init__
, unless there is something preventing it.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.
I did this the only problem was that when using
functools.update_wrapper(self, function)
The FixtureFunctionDefinition will have a
__wrapped__
attribute which will be followed byinspect.unwrap
. I removed this attribute so we don't accidentally unwrap the fixture without using_get_wrapped_function
method.If we don't remove this then we need to be careful to provide
stop
forinspect.unwrap
when it's used.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.
I was actually thinking that
__wrapper__
would be good to have, sinceFixtureFunctionDefinition
is indeed a wrapper. What are the places where it causes an issue? (I can look it up myself a bit later, but in case you tried it already).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.
Please see this commit that fixes the issue: 475deb1
I agree with doing this. Initially I was lazily binding methods, which led me to use
_get_wrapped_function
. Now with binding in the init we can rely oninspect.unwrap
to get the underlying fixture. Less code for us. Thank you for the suggestion.Check warning on line 1810 in src/_pytest/fixtures.py
src/_pytest/fixtures.py#L1809-L1810