Skip to content
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

Conversation

nicoddemus
Copy link
Member

Fix #2699

@coveralls
Copy link

Coverage Status

Coverage remained the same at 91.805% when pulling a993add on nicoddemus:staticmethods-fixtures into 539523c on pytest-dev:master.

@@ -82,7 +82,10 @@ def num_mock_patch_args(function):
return len(patchings)


def getfuncargnames(function, startindex=None):
def getfuncargnames(function, startindex=None, cls=None):
if startindex is None and cls is not None:
Copy link
Member

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

Copy link
Member Author

@nicoddemus nicoddemus Aug 22, 2017

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. 😉

Copy link
Member

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

Copy link
Member Author

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

Oh I see. I decided to move cls here so that callers didn't have to handle known that cls 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 if getfuncargnames also needs a cls argument to figure things out, it should receive it and not require callers to handle that special case themselves.

while reviewing i noticed that this also creates a dependence on how things are named, it will work incorrectly in some cases

Which things? The function name or the argument names?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the function name

Copy link
Member

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 -

Copy link
Member Author

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.

Copy link
Member

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

Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

@@ -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:
Copy link
Member Author

Choose a reason for hiding this comment

The 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 getfuncargnames is an internal utility function used in two places in the code base, it might as well make things simpler for callers to avoid mistakes and keep the calling code clean (as it does here, IMHO).

@nicoddemus
Copy link
Member Author

@RonnyPfannschmidt added the comment like you asked, let me know if you would like to add more information. 👍

@coveralls
Copy link

coveralls commented Sep 5, 2017

Coverage Status

Coverage remained the same at 91.805% when pulling 1fc185b on nicoddemus:staticmethods-fixtures into 539523c on pytest-dev:master.

@RonnyPfannschmidt RonnyPfannschmidt merged commit ad36407 into pytest-dev:master Sep 6, 2017
@RonnyPfannschmidt
Copy link
Member

thanks for the followup yay 👍

@nicoddemus nicoddemus deleted the staticmethods-fixtures branch September 6, 2017 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

staticmethod tests don't work with fixtures
3 participants