From 433cc34aaf0d247181de407378e341911b86c72d Mon Sep 17 00:00:00 2001 From: Jitse Niesen Date: Mon, 8 Apr 2024 22:04:19 +0100 Subject: [PATCH] Move import inside one test inside a function As a side-effect of PR spyder-ide/spyder#21734, a QApplication needs to be running before importing spyder.plugins.preferences.widgets.configdialog. Moving the import inside a function achieves this. --- spyder_unittest/widgets/tests/test_confpage.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/spyder_unittest/widgets/tests/test_confpage.py b/spyder_unittest/widgets/tests/test_confpage.py index 6790a18..9d06311 100644 --- a/spyder_unittest/widgets/tests/test_confpage.py +++ b/spyder_unittest/widgets/tests/test_confpage.py @@ -20,7 +20,6 @@ from spyder.api.plugin_registration.registry import PLUGIN_REGISTRY from spyder.app.cli_options import get_options from spyder.config.manager import CONF -from spyder.plugins.preferences.plugin import Preferences # Local imports from spyder_unittest.unittestplugin import UnitTestPlugin @@ -34,6 +33,10 @@ class MainWindowMock(QMainWindow): register_shortcut = Mock() def __init__(self, parent): + # This import assumes that an QApplication is already running, + # so we can not put it at the top of the file + from spyder.plugins.preferences.plugin import Preferences + super().__init__(parent) self.default_style = None self.widgetlist = [] @@ -75,6 +78,10 @@ def get_plugin(self, plugin_name, error=True): class ConfigDialogTester(QWidget): def __init__(self, parent, main_class, general_config_plugins, plugins): + # This import assumes that an QApplication is already running, + # so we can not put it at the top of the file + from spyder.plugins.preferences.plugin import Preferences + super().__init__(parent) self._main = main_class(self) if main_class else None if self._main is None: