From 189aea36fee1e5f8cf11b75116001ada6886b15a Mon Sep 17 00:00:00 2001 From: Martyn Gigg <martyn.gigg@gmail.com> Date: Wed, 28 Mar 2018 20:38:37 +0100 Subject: [PATCH] Garbage collect after each test requiring a qapp Attempts to fix a random test failure with the jupyter console on macOS by ensuring that widgets are garbage collected promptly. Refs #22063 --- qt/python/mantidqt/utils/qt/testing/__init__.py | 2 ++ qt/python/mantidqt/widgets/test/test_jupyterconsole.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/qt/python/mantidqt/utils/qt/testing/__init__.py b/qt/python/mantidqt/utils/qt/testing/__init__.py index ec30caa54e0..7aee12dd518 100644 --- a/qt/python/mantidqt/utils/qt/testing/__init__.py +++ b/qt/python/mantidqt/utils/qt/testing/__init__.py @@ -20,6 +20,7 @@ from __future__ import absolute_import from inspect import isfunction, ismethod +import gc from qtpy.QtCore import Qt from qtpy.QtWidgets import QApplication @@ -74,6 +75,7 @@ def _requires_qapp_impl(test_method): QAPP = QApplication(['']) test_method(self) QAPP.closeAllWindows() + gc.collect() return _wrapper diff --git a/qt/python/mantidqt/widgets/test/test_jupyterconsole.py b/qt/python/mantidqt/widgets/test/test_jupyterconsole.py index 411e9f4e2e2..c4f2d103ae6 100644 --- a/qt/python/mantidqt/widgets/test/test_jupyterconsole.py +++ b/qt/python/mantidqt/widgets/test/test_jupyterconsole.py @@ -34,16 +34,18 @@ class InProcessJupyterConsoleTest(unittest.TestCase): self.assertTrue(hasattr(widget, "kernel_manager")) self.assertTrue(hasattr(widget, "kernel_client")) self.assertTrue(len(widget.banner) > 0) + del widget def test_construction_with_banner_replaces_default(self): widget = InProcessJupyterConsole(banner="Hello!") self.assertEquals("Hello!", widget.banner) + del widget def test_construction_with_startup_code_adds_to_banner_and_executes(self): widget = InProcessJupyterConsole(startup_code="x = 1") self.assertTrue("x = 1" in widget.banner) self.assertEquals(1, widget.kernel_manager.kernel.shell.user_ns['x']) - + del widget if __name__ == '__main__': unittest.main() -- GitLab