mirror of
https://github.com/beetbox/beets.git
synced 2025-12-16 05:34:47 +01:00
Added a test for multiple plugin classes in a single module.
This commit is contained in:
parent
f5f76f2b85
commit
f7ab1da607
2 changed files with 41 additions and 3 deletions
|
|
@ -399,15 +399,15 @@ def _get_plugin(name: str) -> BeetsPlugin | None:
|
|||
|
||||
if len(plugin_classes) > 1:
|
||||
warnings.warn(
|
||||
f"Plugin {name} defines multiple plugin classes; "
|
||||
f"using the first one found ({plugin_classes[0].__name__})."
|
||||
f"Plugin '{name}' defines multiple plugin classes; "
|
||||
f"using the first one found ({plugin_classes[0].__name__}). "
|
||||
f"This will become an error in beets 3.0.0. Consider exporting "
|
||||
f"the desired plugin class explicitly using `__all__`.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
|
||||
if len(plugin_classes) == 1:
|
||||
if len(plugin_classes) != 0:
|
||||
return plugin_classes[0]()
|
||||
|
||||
except Exception:
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import logging
|
|||
import os
|
||||
import pkgutil
|
||||
import sys
|
||||
from types import ModuleType
|
||||
from unittest.mock import ANY, Mock, patch
|
||||
|
||||
import pytest
|
||||
|
|
@ -523,3 +524,40 @@ class TestImportPlugin(PluginMixin):
|
|||
assert "PluginImportError" not in caplog.text, (
|
||||
f"Plugin '{plugin_name}' has issues during import."
|
||||
)
|
||||
|
||||
|
||||
class MultiPluginModule(ModuleType):
|
||||
class DummyPlugin1(plugins.BeetsPlugin):
|
||||
pass
|
||||
|
||||
class DummyPlugin2(plugins.BeetsPlugin):
|
||||
pass
|
||||
|
||||
def __init__(self, *_, **__):
|
||||
module_name = "beetsplug.multi_export"
|
||||
super().__init__(module_name)
|
||||
self.DummyPlugin1.__module__ = module_name
|
||||
self.DummyPlugin1 = self.DummyPlugin1
|
||||
self.DummyPlugin2 = self.DummyPlugin2
|
||||
self.DummyPlugin2.__module__ = module_name
|
||||
|
||||
|
||||
class TestMultiPluginExport(PluginMixin):
|
||||
"""Test that exporting multiple plugins from a single namespace
|
||||
raises a warning.
|
||||
|
||||
TODO: Change to raises an error on migration to 3.0.0
|
||||
"""
|
||||
|
||||
plugin = "multi_export"
|
||||
|
||||
@pytest.fixture(autouse=True, scope="class")
|
||||
def setup(self):
|
||||
with patch.dict(
|
||||
sys.modules, {"beetsplug.multi_export": MultiPluginModule()}
|
||||
):
|
||||
yield
|
||||
|
||||
def test_multi_plugin_export(self):
|
||||
with pytest.deprecated_call():
|
||||
self.load_plugins("multi_export")
|
||||
|
|
|
|||
Loading…
Reference in a new issue