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
fix overridden/extended fixtures #12110
base: main
Are you sure you want to change the base?
fix overridden/extended fixtures #12110
Conversation
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.
Thanks for the PR @andresliszt.
As currently implemented, this will potentially add too many names to the closure (where previously it would potentially miss some). This can happen if we have e.g. 3 levels of overrides (e.g. conftest, module, class), where -1 uses -2 but -2 doesn't use -3, and -3 has some extra dependencies. The current code adds -3's dependencies, but it shouldn't.
Hey hello!, i think is handled, all additions are made with respect to -1. If -2 doesn't use -3, it will never be considered. I updated the tests with your example. |
In the code as written it is added -- it is iterating over all fixturedefs and adding all of their argnames. You can verify by putting a breakpoint and seeing that the closure includes The reason |
Thanks for your answer i really like to know more about this amazing project!. The last question I have is this, the inner function i created is called with the result of this fixturedefs = self.getfixturedefs(argname, parentnode)
>>> fixturedefs
(<FixtureDef argname='main' scope='function' baseid='example/test.py'>, <FixtureDef argname='main' scope='function' baseid='example/test.py::TestFoo'>) As i understand the function
is it iterarting over all fixturedefs or iteraring over all fixturedefs of the current node? |
It gives the fixtures that the node may depend on, so it returns the 3 mains. The reason for this is that a test may use
I checked it myself now (with your revised test), and I see
The function is this: def dependent_fixtures_argnames(
fixture_defs: Sequence[FixtureDef[Any]],
) -> List[str]:
last_fixture = fixture_defs[-1]
# Initialize with the argnames of the last fixture
dependent_argnames = list(last_fixture.argnames)
for arg in fixture_defs:
if arg.argname in last_fixture.argnames:
# Add new argument names maintaining order and avoiding duplicates
for argname in arg.argnames:
if argname not in dependent_argnames:
dependent_argnames.append(argname)
return dependent_argnames Where |
You are absolutely right @bluetech ! In my example i forgot to add |
ec7c372
to
c0daf28
Compare
Thanks for the update. Now there is a different problem. The code handles the case of |
This PR aims to solve this issue #12091. In the issue example shown below,
fixturedefs
defined here was returning a tuple of the two versions of the overriddenmain
fixture. The dependency onparam
was in the first element of the tuple, so doingfixture_defs[-1]
would never find that dependency due to name duplication. The change is quite simple, checks in the tuple all fixturedefs whoseargname
is contained infixture_defs[-1].argnames