Skip to content

fixtures: fix parametrization losing (static) transitive dependencies from overridden fixtures#14369

Open
bluetech wants to merge 6 commits intopytest-dev:mainfrom
bluetech:fixture-override-with-parametrization
Open

fixtures: fix parametrization losing (static) transitive dependencies from overridden fixtures#14369
bluetech wants to merge 6 commits intopytest-dev:mainfrom
bluetech:fixture-override-with-parametrization

Conversation

@bluetech
Copy link
Copy Markdown
Member

@bluetech bluetech commented Apr 8, 2026

This PR fixes #14248.

The 1st commit adds the xfailed test from @smarie in the issue.

The 2nd and 3rd commits do some related test cleanup.

The 4th commit is the actual fix. Basically, just making prune_dependency_tree use the same underlying code as the already-fixed getfixtureclosure.

The 5th commit is some optimizations that I split to make the previous commit minimal.

The 6th commit is a bit of a consistency fix and optimization, changing the static fixture order to fully DFS like the dynamic one.

Sylvain MARIE and others added 6 commits April 8, 2026 12:23
…th overrides and parametrization

Based on existing tests, just adding the parametrization.

Refs pytest-dev#14248.
…n_ordering

No functional changes, just making it easier to follow.
…es without monkeypatching

Seems better to avoid this
monkeypatch-pytest-to-smuggle-info-out-of-pytester pattern.
… from overridden fixtures

As the xfail'ed test
`test_fixture_closure_with_overrides_and_parametrization` demonstrates,
adding any direct parametrization causes the statically computed fixture
closure to omit transitive dependencies from overridden (but still
requested) fixtures. (The dynamic algorithm does get it right).

The `prune_dependency_tree()` function did not account for overridden
fixtures properly (only checked `-1`). Make it share the core recursive
DFS traversal used by `getfixtureclosure()`, which already fixed a
similar problem (pytest-dev#13789).

An alternative solution is to replace `prune_dependency_tree` wholesale
with another call to `getfixtureclosure`, as proposed in PR pytest-dev#11243,
however it's somewhat harder to get working, so let's go with this
solution for now.

Fix pytest-dev#14248
Didn't include this in the previous commit, in case it causes
regressions.
(I am talking here about `names_closure`/`fixturenames`.)

Before 72ae3db, the static traversal
order was BFS (unlike the dynamic order which is DFS). So it was natural
that `initialnames` was always at the beginning of the closure, since it
consists the initial working set. When we changed to DFS, we kept this.
But it's a bit weird, now the initialnames are in BFS, but all
transitive dependencies are in DFS.

Remove this special case, making both the static and dynamic order fully
DFS.
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] prune_dependency_tree's behaviour conflicts with the latest improvements in getfixtureclosure (pytest 9.x)

1 participant