Test speedup: cache config.sources in ConfigMixin#6772
Conversation
|
Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry. |
There was a problem hiding this comment.
Pull request overview
PR try make tests faster and more isolated by building fresh beets.config per test without paying full config.read() cost each time. grug like less time waste, but current ConfigMixin.config reset look wrong: it can grow config.sources every test and poke private confuse cache with wrong type, so suite may get flaky / slow over time.
Changes:
- Cache a “baseline”
config.sourcesonce inConfigMixin, and rebuild test config from that baseline. - Switch
configfixture to function scope (fresh config per test case / param set). - Update a few tests to match new per-test config lifecycle.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
beets/test/helper.py |
Add cached baseline for config sources; rebuild per-test config from baseline. |
test/conftest.py |
Make config fixture function-scoped. |
test/autotag/test_distance.py |
Adjust fixture scope to match function-scoped config. |
test/plugins/test_lastgenre.py |
Remove now-unneeded “fresh config per param” shim fixture. |
test/plugins/test_lyrics.py |
Update test to use plugin config context + per-test state. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #6772 +/- ##
==========================================
+ Coverage 74.78% 74.98% +0.19%
==========================================
Files 163 163
Lines 20966 20966
Branches 3302 3302
==========================================
+ Hits 15680 15721 +41
+ Misses 4529 4486 -43
- Partials 757 759 +2 🚀 New features to boost your workflow:
|
8d9429c to
a2ce444
Compare
ad8438d to
163f9ac
Compare
|
This feels a little like we're working around pytest's intended fixture model. Would it make sense to use a session-scoped config as the canonical instance and have function-scoped configs operate on copies of it? That would achieve essentially the same behavior as the current approach while staying within pytest's fixture-scoping semantics. |
It does, however this is out of scope of this PR. I actually tried doing this and found that we have the same issue that we had with @cached_property
def config(self) -> beets.IncludeLazyConfig:
return self.request.getfixturevalue("config") |
5ded4f0 to
97b2430
Compare
63b72cc to
38c290a
Compare
ConfigMixin, which now caches a defaultconfig.sourcesbaseline once and rebuilds isolated test config from that baseline for each test instead of re-reading full config every time.configfixture is now function-scoped, giving each test and parametrized case a fresh config by default.test/autotag/test_distance.py,test/plugins/test_lastgenre.py, andtest/plugins/test_lyrics.pyto use the new isolated flow, since per-test config setup is no longer too expensive.High-level impact
2xby avoiding repeated full config reads while keeping fresh per-test state.See two test modules, for example, where
ConfigMixinis used extensively:Before
After