Move fixture cache from FixtureDef to SetupState#14770
Conversation
c54967f to
6678e5d
Compare
There was a problem hiding this comment.
Good find, thanks @RonnyPfannschmidt !
I pushed 5 additional commits. The tracking of the currently active request parameter for --setup-show is no longer attached to FixtureDef. Instead, --setup-show uses the existing SetupState.fixture_cache, which already contains the active fixture param as a cache key. The variable naming was changed from "cache_key" to "param" or "active_param".
In order to distinguish between "no param" and "param=None", I introduced a sentinel value. This prevents --setup-show from printing my_fixture[None] for unparametrized fixtures.
|
Previous stalled PR you might want to use as a reference/comparison: #14104 |
|
Thanks @bluetech! This topic was raised during the pytest sprint and I wasn't aware that there have been previous attempts at this. I'll check out the PR. |
Use _invalidate_fixture_cache instead.
… to FixtureRequest.
…Def to SubRequest
…the result is successful or an exception.
…he responsibility of FixtureRequest.
…he_value and _cache_exception, respectively
…of SetupState, instead of FixtureDef.
…it about the contents of the cache key.
…hing fixture results to distinguish between *no param* and *None*.
…arams for --setup-show.
cf3854d to
61286bd
Compare
This PR removes FixtureDef.cached_result in favor of a cache that is attached to SetupState. FixtureRequest received methods to manipulate the fixture cache.
The PR is easiest reviewed commit by commit.
Open issues
Previously, fixture values were cached as part of FixtureDef objects and the cache entries contained a cache_key. The cache key is either None for non-parametrized fixtures or SubRequest.param. This allows invalidating cache entries when fixture parameters change.
Hoisting up the fixture cache to SetupState technically makes FixtureDef part of the cache key. This means we should use a two-dimensional index (e.g. tuple[FixtureDef, param]) to store entries in the fixture cache. Unfortunately, this is tricky, because TopRequest doesn't know about the current fixture param and therefore doesn't know the cache key.
This work has been done as part of the pytest sprint 2026, sponsored by Omicron.