-
-
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
Allow tests declared as @staticmethod to use fixtures #2700
Merged
RonnyPfannschmidt
merged 2 commits into
pytest-dev:master
from
nicoddemus:staticmethods-fixtures
Sep 6, 2017
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -957,11 +957,7 @@ def __init__(self, session): | |
|
||
def getfixtureinfo(self, node, func, cls, funcargs=True): | ||
if funcargs and not hasattr(node, "nofuncargs"): | ||
if cls is not None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's what I mean about the "split" responsibility. Note as well that |
||
startindex = 1 | ||
else: | ||
startindex = None | ||
argnames = getfuncargnames(func, startindex) | ||
argnames = getfuncargnames(func, cls=cls) | ||
else: | ||
argnames = () | ||
usefixtures = getattr(func, "usefixtures", None) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Allow tests declared as ``@staticmethod`` to use fixtures. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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 bit should be documented as a hack and factored out when revisiting fixtures
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.
Why is it a hack? It is not entirely clear to me why it this is there and I would like to document it properly then. 😉
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.
it moves a new responsibility into getfuncargnames, and fills the code with a lot of conditionals that are strictly not needed at that place and interaction
while reviewing i noticed that this also creates a dependence on how things are named, it will work incorrectly in some cases
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.
Oh I see. I decided to move
cls
here so that callers didn't have to handle known thatcls
might affect the results of this call themselves; the previous code was splitting that responsibility between two places,getfixtureinfo
in_pytest/fixtures.py
and here (see the diff). IMHO ifgetfuncargnames
also needs acls
argument to figure things out, it should receive it and not require callers to handle that special case themselves.Which things? The function name or the argument names?
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 function 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.
@nicoddemus from my pov the fixture mechanism should ask the node for the requested fixtures, not extract it somewhere down the line from the function object, in fact it should never even see the function object simply to separate concerns -
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 see thanks. But from my understanding this is quite a refactor on how fixture names are obtained and out of scope of this PR.
This PR attempts to fix fixture support for static methods and doesn't add complexity to the current system IMHO. If you disagree we should close this PR, which I'm OK with.
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.
im fine with the pr, i just want to see a note there detailing what is made worse to get it done