Skip to content

Commit

Permalink
Merge pull request #2490 from CyclingNinja/test_loadplugins
Browse files Browse the repository at this point in the history
Prevents duplicate loading of plugins
  • Loading branch information
astrofrog authored May 9, 2024
2 parents 7a834e7 + a2ddda8 commit c2c5cfa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions glue/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def load_plugins(splash=None, require_qt_plugins=False, plugins_to_load=None):
config = PluginConfig.load()

if plugins_to_load is None:
plugins_to_load = [i.value for i in list(iter_plugin_entry_points())]
plugins_to_load = [i.module for i in list(iter_plugin_entry_points())]
if require_qt_plugins:
plugins_to_require = [*REQUIRED_PLUGINS, *REQUIRED_PLUGINS_QT]
else:
Expand All @@ -59,7 +59,8 @@ def load_plugins(splash=None, require_qt_plugins=False, plugins_to_load=None):
n_plugins = len(plugins_to_require)

for i_plugin, item in enumerate(list(iter_plugin_entry_points())):
if item.value.replace(':setup', '') in plugins_to_load:

if item.module in plugins_to_load:
if item.module not in _installed_plugins:
_installed_plugins.add(item.name)

Expand Down
20 changes: 20 additions & 0 deletions glue/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from unittest.mock import patch

from glue.main import load_plugins


def test_no_duplicate_loading(capsys):
"""
Regression test for duplicated loading of plugins
on subsequent calls of `load_plugins()` after initial
glue-qt startup.
"""
from glue.logger import logger

with patch.object(logger, 'info') as info:
load_plugins()

for acall in info.call_args_list:
if 'Loading plugin' in acall[0][0]:
assert 'failed' in acall[0][0]

0 comments on commit c2c5cfa

Please sign in to comment.