Skip to content

Commit 44adb62

Browse files
committed
Added UNIT_TESTING module variable
This variable is True if we are running unittests. This should avoid the creation of too many UrlHelp instances. The latter spawns processes that are not properly closed by PyQt and as such remain in memory causing potentially large overheads.
1 parent 50d5b6b commit 44adb62

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

psyplot_gui/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,11 @@ def get_parser(create=True):
362362
return parser
363363

364364

365+
#: A boolean variable to check if the GUI is tested. This is set automatically
366+
#: true on CI services
367+
UNIT_TESTING = os.getenv('CI')
368+
369+
365370
#: Disable the default for the ListGuiPluginsAction on RTD, because it looks
366371
#: better in the docs
367372
_on_rtd = os.environ.get('READTHEDOCS', None) == 'True'

psyplot_gui/common.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
import io
2020

2121

22+
def is_running_tests():
23+
"""Check if there are any GUI tests running
24+
25+
This function returns the :attr:`psyplot_gui.UNIT_TESTING` variable"""
26+
import psyplot_gui
27+
return psyplot_gui.UNIT_TESTING
28+
29+
2230
def get_module_path(modname):
2331
"""Return module `modname` base path"""
2432

psyplot_gui/help_explorer.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
from psyplot_gui.common import get_icon, DockMixin, PyErrorMessage
2323
from IPython.core.oinspect import signature, getdoc
2424
import logging
25-
from psyplot_gui.common import get_module_path, StreamToLogger
25+
from psyplot_gui.common import get_module_path, StreamToLogger, \
26+
is_running_tests
2627
from tempfile import mkdtemp
2728
try:
2829
from sphinx.application import Sphinx
@@ -62,6 +63,9 @@ def html2file(url):
6263
p.path[int(sys.platform == 'win32'):]))
6364

6465

66+
_viewers = OrderedDict()
67+
68+
6569
logger = logging.getLogger(__name__)
6670

6771

@@ -917,9 +921,20 @@ def __init__(self, *args, **kwargs):
917921
self.vbox = vbox = QVBoxLayout()
918922
self.combo = QComboBox(parent=self)
919923
vbox.addWidget(self.combo)
920-
self.viewers = OrderedDict(
921-
[(key, cls(parent=self)) for key, cls in six.iteritems(
922-
self.viewers)])
924+
if _viewers:
925+
self.viewers = _viewers
926+
for w in self.viewers.values():
927+
w.setParent(self)
928+
else:
929+
self.viewers = OrderedDict(
930+
[(key, cls(parent=self)) for key, cls in six.iteritems(
931+
self.viewers)])
932+
# save the UrlHelp because QWebEngineView creates child processes
933+
# that are not properly closed by PyQt and as such use too much
934+
# memory
935+
if is_running_tests():
936+
for key, val in self.viewers.items():
937+
_viewers[key] = val
923938
for key, ini in six.iteritems(self.viewers):
924939
self.combo.addItem(key)
925940
ini.hide()

tests/_base_testing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ def setUpClass(cls):
5454
cls._close_app = mainwindow is None
5555
cls._app = QApplication.instance()
5656
if not running_in_gui:
57+
import psyplot_gui
58+
psyplot_gui.UNIT_TESTING = True
5759
if cls._app is None:
5860
cls._app = QApplication([])
5961
cls._app.setQuitOnLastWindowClosed(False)

0 commit comments

Comments
 (0)