tests: replace function-scoped helper fixtures with TestHelper#6709
tests: replace function-scoped helper fixtures with TestHelper#6709snejus wants to merge 7 commits into
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. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #6709 +/- ##
==========================================
+ Coverage 74.52% 74.71% +0.18%
==========================================
Files 162 162
Lines 20818 20818
Branches 3295 3295
==========================================
+ Hits 15515 15554 +39
+ Misses 4547 4505 -42
- Partials 756 759 +3 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
grug see PR make test setup less copy-paste. instead of local helper fixtures per file, tests now inherit shared helper classes (TestHelper/PluginTestHelper) and migration tests get one common harness.
Changes:
- swap function-scoped
helperfixtures for TestHelper / PluginTestHelper base classes in plugin tests - add
MigrationTestHelperharness so each migration test only defines legacy setup + migration under test - adjust playcount tests to use class-based helper + explicit
logfixture injection
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/plugins/utils/test_playcount.py | move from helper fixture to TestHelper inheritance; pass logger via fixture |
| test/plugins/test_missing.py | use shared PluginTestHelper (plus IO mixin) for missing plugin CLI tests |
| test/plugins/test_fuzzy.py | use PluginTestHelper for fuzzy plugin tests; remove local helper fixture |
| test/library/test_migrations.py | introduce MigrationTestHelper and refactor migrations tests onto shared harness |
9080832 to
2ad2368
Compare
- Replace local setup fixtures with existing test helper base classes to reduce duplicated test setup.
- Centralize migration test setup in a shared helper and update the migration tests to use the common pre-migration initialization flow. - This removes repeated fixture boilerplate while keeping each test focused on the migration behavior it verifies.
- Replace duplicate pytest import helper fixtures with PluginMixin-based setup helpers. - Keep plugin import tests aligned with shared beets setup behavior.
2ad2368 to
980d256
Compare
- Dropped unused MusicBrainZ and Subsonic test helpers and imports. - Keeps plugin test modules focused on the behavior they still exercise.
980d256 to
3f4d9d5
Compare
semohr
left a comment
There was a problem hiding this comment.
I like the introduction of these <scope>_helper fixtures in general. I'm just not entirely sure how the scopes were chosen based on where the fixtures are actually used. To me, it looks like most of them could probably use session scope. 🤔
I did a quick experiment and changed the fixture in test_random to session, and I didn't run into any issues. Maybe there's a reason for the more restrictive scopes that I'm missing?
| helper.setup_beets() | ||
| yield helper | ||
| helper.teardown_beets() | ||
| @pytest.fixture(scope="session") |
There was a problem hiding this comment.
Why the indirection? Couldn't we use session_helper directly?
There was a problem hiding this comment.
The indirection is intentional: it keeps each test module using the stable local helper fixture name while delegating lifecycle/scope to the shared helper fixtures. That means the rest of the module does not need to know whether the backing helper is session-, module-, or class-scoped.
If we used session_helper directly, that scope detail would spread through the module and future scope changes would require broader fixture/test renames. With this shape, changing scope requires adjusting these 3 lines only:
@pytest.fixture(scope="session")
def helper(session_helper):
return session_helper| helper.setup_beets() | ||
| yield helper | ||
| helper.teardown_beets() | ||
| def helper(module_helper): |
There was a problem hiding this comment.
Same here again some unneeded indirection imo. Im also wondering now why we need the helper on different scopes in the first place. Have you tried session scope here? Do we have sideffect here which we dont want to propagate to the session scope?
| return check_import | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") |
There was a problem hiding this comment.
Maybe we add a bit of doc strings here on when we expect them to be used?
helperfixtures.test/library/test_migrations.pynow usesMigrationTestHelperto provide one common migration harness, with each test class defining only the legacy state and migration it needs.test/plugins/test_fuzzy.py,test/plugins/test_missing.py, andtest/plugins/utils/test_playcount.pynow rely on shared helpers likePluginTestHelperandTestHelperfor common setup.Note: I kept these fixtures in these files
test_query.pyplugins/test_random.pyplugins/test_aura.pyplugins/test_lyrics.pybecause they intentionally use a higher
scope, for example intest_query.py:Using this setup pattern in
test_query.pysignificantly improved testing durations.Architecture impact
High-level outcome