|
19 | 19 | import os |
20 | 20 | import pkgutil |
21 | 21 | import sys |
| 22 | +from types import ModuleType |
22 | 23 | from unittest.mock import ANY, Mock, patch |
23 | 24 |
|
24 | 25 | import pytest |
@@ -523,3 +524,44 @@ def test_import_plugin(self, caplog, plugin_name): |
523 | 524 | assert "PluginImportError" not in caplog.text, ( |
524 | 525 | f"Plugin '{plugin_name}' has issues during import." |
525 | 526 | ) |
| 527 | + |
| 528 | + |
| 529 | +class MultiPluginModule(ModuleType): |
| 530 | + class DummyPlugin1(plugins.BeetsPlugin): |
| 531 | + pass |
| 532 | + |
| 533 | + class DummyPlugin2(plugins.BeetsPlugin): |
| 534 | + pass |
| 535 | + |
| 536 | + def __init__(self, *_, **__): |
| 537 | + module_name = "beetsplug.multi_export" |
| 538 | + super().__init__(module_name) |
| 539 | + self.DummyPlugin1.__module__ = module_name |
| 540 | + self.DummyPlugin1 = self.DummyPlugin1 |
| 541 | + self.DummyPlugin2 = self.DummyPlugin2 |
| 542 | + self.DummyPlugin2.__module__ = module_name |
| 543 | + |
| 544 | + |
| 545 | +class TestMultiPluginExport(PluginTestCase): |
| 546 | + """Test that exporting multiple plugins from a single namespace |
| 547 | + raises a warning. |
| 548 | +
|
| 549 | + TODO: Change to raises an error on migration to 3.0.0 |
| 550 | + """ |
| 551 | + |
| 552 | + plugin = "multi_export" |
| 553 | + |
| 554 | + @classmethod |
| 555 | + def setUpClass(cls): |
| 556 | + patcher = patch.dict( |
| 557 | + sys.modules, {"beetsplug.multi_export": MultiPluginModule()} |
| 558 | + ) |
| 559 | + patcher.start() |
| 560 | + cls.addClassCleanup(patcher.stop) |
| 561 | + |
| 562 | + super().setUpClass() |
| 563 | + |
| 564 | + @pytest.mark.filterwarnings("ignore") |
| 565 | + def test_multi_plugin_export(self): |
| 566 | + with self.assertWarns(DeprecationWarning): |
| 567 | + self.load_plugins("multi_export") |
0 commit comments