Skip to content

Conversation

@semohr
Copy link
Contributor

@semohr semohr commented Sep 17, 2025

This PR addresses historical testing debt in test_plugins.py by standardizing plugin test infrastructure.

  • Introduces PluginTestCasePytest, deprecating the older PluginTestCase (unittest-based) to unify tests under pytest.
  • Enhances PluginMixin with programmatic plugin registration/unregistration while still working through standard load_plugins, improving test isolation and avoiding fragile disk/module hacks.
  • Simplifies and modernizes individual tests where possible, reducing boilerplate and making future plugin tests easier to extend.

There is still the PromptChoicesTest left which I have not touched (this one scares me 👻).

Coverage:

# before
Name               Stmts   Miss Branch BrPart   Cover   Missing
---------------------------------------------------------------
beets/plugins.py     228     57     70      6  70.13%   119, 131-136, 184->186, 186->188, 188->191, 279-282, 299-305, 315-321, 352, 366-387, 473-475, 489, 523-529, 544-547, 575-578, 595-607
---------------------------------------------------------------
TOTAL                228     57     70      6  70.13%

# after
Name               Stmts   Miss Branch BrPart   Cover   Missing
---------------------------------------------------------------
beets/plugins.py     228     45     70      8  74.83%   131-136, 184->186, 186->188, 188->191, 279-282, 286->exit, 299-305, 315-321, 352, 372->387, 473-475, 489, 523-529, 544-547, 575-578, 595-607
---------------------------------------------------------------
TOTAL                228     45     70      8  74.83%

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Sep 17, 2025

Reviewer's Guide

This PR refactors the plugin test suite by migrating from unittest to pytest (introducing PluginTestCasePytest and deprecating the old TestCase), augments the PluginMixin helper with dynamic registration/unregistration and context managers for better isolation, and modernizes individual tests through fixtures, parametrization, and reduced boilerplate.

File-Level Changes

Change Details Files
Introduce pytest-based test harness and deprecate unittest infrastructure
  • Add PluginTestCasePytest with an autouse fixture for setup/teardown
  • Switch test classes to inherit from PluginTestCasePytest instead of PluginTestCase
  • Remove setUp methods and migrate to pytest fixtures and markers
test/test_plugins.py
beets/test/helper.py
Enhance PluginMixin for dynamic plugin management
  • Implement register_plugin/unregister_plugin/unregister_all_plugins to manage sys.modules entries
  • Add plugins() context manager for scoped plugin loading and unloading
  • Provide get_plugin_instance helper and improve load_plugins/unload_plugins behavior
beets/test/helper.py
Modernize individual plugin tests with fixtures, context managers, and parametrization
  • Wrap plugin-specific tests in self.plugins(...) context manager instead of manual registration
  • Replace repetitive listener tests with @pytest.mark.parametrize and simplified assertions
  • Simplify prompt choice and import-plugin tests to use with self.plugins and pytest fixtures
test/test_plugins.py

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions
Copy link

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
Copy link

codecov bot commented Sep 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.48%. Comparing base (394d78d) to head (8de2a14).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6022      +/-   ##
==========================================
- Coverage   66.52%   66.48%   -0.04%     
==========================================
  Files         117      117              
  Lines       18084    18084              
  Branches     3061     3061              
==========================================
- Hits        12030    12023       -7     
- Misses       5403     5409       +6     
- Partials      651      652       +1     

see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant