-
-
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
added indicative error when parametrizing an argument with a default … #3367
added indicative error when parametrizing an argument with a default … #3367
Conversation
_pytest/compat.py
Outdated
# Note: this code intentionally mirrors the code at the beginning of getfuncargnames, | ||
# to get the arguments which were excluded from its result because they had default values | ||
return tuple(p.name for p in signature(function).parameters.values() | ||
if (p.kind is Parameter.POSITIONAL_OR_KEYWORD or |
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.
lets use a in check here instead of 2 is checks
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.
Looks good @brianmaissy, just a few minor comments.
Should we target master
? This just improves the existing error message after all.
Also, can you post the full output of the error?
_pytest/python.py
Outdated
@@ -797,13 +797,16 @@ def parametrize(self, argnames, argvalues, indirect=False, ids=None, | |||
valtypes = {} | |||
for arg in argnames: | |||
if arg not in self.fixturenames: | |||
if isinstance(indirect, (tuple, list)): | |||
name = 'fixture' if arg in indirect else 'argument' | |||
if arg in getdefaultargnames(self.function): |
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 move getdefaultargnames
out of the loop and store it into a set
, no need to recompute it again during each iteration.
_pytest/compat.py
Outdated
@@ -127,6 +127,15 @@ def getfuncargnames(function, is_method=False, cls=None): | |||
return arg_names | |||
|
|||
|
|||
def getdefaultargnames(function): |
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.
We are using pep8 names now, so please change this to get_default_arg_names
6317aa0
to
d3fb77f
Compare
d3fb77f
to
857098f
Compare
bump? |
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 gentle ping
Thanks @brianmaissy for the PR and @RonnyPfannschmidt for the ping. 😁 |
Fixes #3221