Allow load_fixture to switch fixture path for already-loaded models#79
Merged
byroot merged 1 commit intobyroot:masterfrom Mar 12, 2026
Merged
Conversation
When load_fixture is called for a model that is already cached but with a different alternate_base_path, it now unloads the previous fixture and loads from the new path. Previously, the second call was silently ignored regardless of path, leaving stale fixture data from the first call. Calls with the same path remain a no-op (preserving the existing optimization).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TestHelper.load_fixturenow unloads and reloads when called for an already-cached model with a differentalternate_base_path. Previously, the second call was silently ignored regardless of path, leaving stale data from the first load.Problem
When two different test setups call
load_fixturefor the same model class but with different fixture paths, the second call is silently skipped because the cache only checks@cache.key?(model_class)— it doesn't compare paths:This is a footgun in test suites where execution order is randomized and different test groups use different fixture directories for the same FrozenRecord model.
Fix
When
load_fixtureis called for a model already in the cache, compare the currently loadedbase_pathagainst the requestedalternate_base_path. If they match, return early (no-op). If they differ, callunload_fixturefirst to restore the originalbase_path, then proceed with the new load. The originalbase_path(forunload_fixturesteardown) is preserved correctly becauseunload_fixturerestores it before the re-load captures a new snapshot.Tests
unload_fixturesstill restores the originalbase_pathafter path switches