Skip to content

Avoiding looking upwards for parameter argnames when generating fixtu… #5254

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

Merged

Conversation

Sup3rGeo
Copy link
Member

@Sup3rGeo Sup3rGeo commented May 12, 2019

…reinfo.

Closes #5036

Basically even though there is code to check if a fixture is a parameter name:

pytest/src/_pytest/fixtures.py

Lines 1218 to 1231 in 6a43c8c

if fixturedef.params is not None:
markers = list(metafunc.definition.iter_markers("parametrize"))
for parametrize_mark in markers:
if "argnames" in parametrize_mark.kwargs:
argnames = parametrize_mark.kwargs["argnames"]
else:
argnames = parametrize_mark.args[0]
if not isinstance(argnames, (tuple, list)):
argnames = [
x.strip() for x in argnames.split(",") if x.strip()
]
if argname in argnames:
break

The problem is that any other higher level dependant fixtures would also be included in the
metafunc.fixturenames for the function, and because of course the name of this higher fixture does not match the parametrization parameter, the function would be erroneously additionally parametrized.

///

  • Create a new changelog file in the changelog folder, with a name like <ISSUE NUMBER>.<TYPE>.rst. See changelog/README.rst for details.
  • Target the master branch for bug fixes, documentation updates and trivial changes.
  • Target the features branch for new features and removals/deprecations.
  • Include documentation when adding new features.
  • Include new tests or update existing tests when applicable.

Unless your change is trivial or a small documentation fix (e.g., a typo or reword of a small section) please:

  • Add yourself to AUTHORS in alphabetical order;

@codecov
Copy link

codecov bot commented May 13, 2019

Codecov Report

Merging #5254 into master will increase coverage by 1.99%.
The diff coverage is 69.56%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5254      +/-   ##
==========================================
+ Coverage   91.21%   93.21%   +1.99%     
==========================================
  Files         115      115              
  Lines       26282    26303      +21     
  Branches     2589     2592       +3     
==========================================
+ Hits        23974    24519     +545     
+ Misses       1983     1462     -521     
+ Partials      325      322       -3
Impacted Files Coverage Δ
src/_pytest/fixtures.py 95.65% <100%> (-2.28%) ⬇️
src/_pytest/mark/structures.py 92.65% <100%> (+0.12%) ⬆️
testing/python/fixtures.py 77.75% <12.5%> (-20.76%) ⬇️
testing/logging/test_reporting.py 20.99% <0%> (-79.01%) ⬇️
testing/examples/test_issue519.py 33.33% <0%> (-66.67%) ⬇️
testing/python/show_fixtures_per_test.py 41.17% <0%> (-58.83%) ⬇️
testing/test_warnings.py 55.19% <0%> (-40.44%) ⬇️
src/_pytest/logging.py 85.38% <0%> (-9.64%) ⬇️
testing/logging/test_fixture.py 93.1% <0%> (-6.9%) ⬇️
... and 24 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 654d8da...65bd1b8. Read the comment docs.

@Sup3rGeo Sup3rGeo requested a review from nicoddemus May 13, 2019 16:54
@Sup3rGeo
Copy link
Member Author

Basically the two failing tests are problems with the CI themselves it seems.

Anyways, I think this is functional enough so someone can just review it?

@Sup3rGeo
Copy link
Member Author

Closing and reopening to trigger CI

@Sup3rGeo Sup3rGeo closed this May 20, 2019
@Sup3rGeo Sup3rGeo reopened this May 20, 2019
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.

Excellent work @Sup3rGeo, really sorry about the delay on this. 👍

Please take a look at my suggestions and let me know what you think.

@nicoddemus
Copy link
Member

Also please squash your commits and rebase on master. 😁

@blueyed
Copy link
Contributor

blueyed commented May 30, 2019

Thanks for this!
It is still not squashed though..

@blueyed
Copy link
Contributor

blueyed commented May 30, 2019

(wouldn't be a problem if we could do it from the UI (#4361))

@nicoddemus
Copy link
Member

@Sup3rGeo would you mind squashing/rebasing one last time? Feel free to merge it yourself once CI is green again. 😁

@Sup3rGeo
Copy link
Member Author

Sure! I was waiting to do this the very last thing, after checking if CI passed, which it did so I will do it now

@Sup3rGeo Sup3rGeo force-pushed the bugfix/fixture-param-clash-5036 branch from 505ee0a to 5bf88e9 Compare May 30, 2019 17:23
@blueyed
Copy link
Contributor

blueyed commented May 30, 2019

Looks like you've rebased it on features?

@nicoddemus
Copy link
Member

Looks like it. Problem is that now all commits have been rewritten 😬

@blueyed
Copy link
Contributor

blueyed commented May 30, 2019

Well, it should go to master, no?
Should be just rebased again properly then.
Or do you mean to have it in features instead?

(wouldn't be a problem if we could do it from the UI (#4361)) - so maybe @asottile / @RonnyPfannschmidt should take over.. ;)

@asottile asottile force-pushed the bugfix/fixture-param-clash-5036 branch from 5bf88e9 to eb5c797 Compare May 30, 2019 20:58
@Sup3rGeo
Copy link
Member Author

Hahaha sorry guys looks like I screwed big time, thanks @asottile for fixing it up.

@Sup3rGeo
Copy link
Member Author

Found a mistake in a test, I will commit the fix and squash (properly this time)

@Sup3rGeo Sup3rGeo force-pushed the bugfix/fixture-param-clash-5036 branch from eb5c797 to 65bd1b8 Compare May 30, 2019 21:43
@Sup3rGeo
Copy link
Member Author

Ok hope I did right this time (sorry for this mess). If no one objects, I will do as @nicoddemus said and merge this if CI becomes green.

@nicoddemus
Copy link
Member

Looks good! Please go ahead with the merge once it's green. 👍

@nicoddemus nicoddemus merged commit f360147 into pytest-dev:master May 31, 2019
@Sup3rGeo Sup3rGeo deleted the bugfix/fixture-param-clash-5036 branch May 31, 2019 09:03
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.

pytest.mark.parametrize does not correctly hide fixtures of the same name (it misses its dependencies)
3 participants