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

added indicative error when parametrizing an argument with a default … #3367

Conversation

brianmaissy
Copy link
Contributor

Fixes #3221

@coveralls
Copy link

coveralls commented Apr 4, 2018

Coverage Status

Coverage increased (+0.06%) to 92.856% when pulling 857098f on brianmaissy:feature/indicative_error_for_parametrize_with_default_argument into 36f6687 on pytest-dev:master.

# 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
Copy link
Member

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

Copy link
Member

@nicoddemus nicoddemus left a 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?

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

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.

@@ -127,6 +127,15 @@ def getfuncargnames(function, is_method=False, cls=None):
return arg_names


def getdefaultargnames(function):
Copy link
Member

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

@brianmaissy brianmaissy force-pushed the feature/indicative_error_for_parametrize_with_default_argument branch from 6317aa0 to d3fb77f Compare April 12, 2018 10:08
@brianmaissy brianmaissy changed the base branch from features to master April 15, 2018 17:46
@brianmaissy brianmaissy force-pushed the feature/indicative_error_for_parametrize_with_default_argument branch from d3fb77f to 857098f Compare April 15, 2018 17:53
@brianmaissy
Copy link
Contributor Author

bump?

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.

@nicoddemus gentle ping

@nicoddemus nicoddemus merged commit 2a480c5 into pytest-dev:master Apr 23, 2018
@nicoddemus
Copy link
Member

Thanks @brianmaissy for the PR and @RonnyPfannschmidt for the ping. 😁

@brianmaissy brianmaissy deleted the feature/indicative_error_for_parametrize_with_default_argument branch April 23, 2018 20:44
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.

4 participants