Skip to content

Commit c73e05f

Browse files
System Tests: run tests "offscreen" on Windows OS to prevent popups (#2804)
2 parents 32a6509 + 0fb2d8e commit c73e05f

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ test-verbose:
5151
test-system:
5252
${XVFBRUN} python -m pytest -vs -rs -p no:xdist -p no:randomly -p no:repeat -p no:cov -o log_cli=true --run-system-tests mantidimaging/gui/test/
5353

54+
test-system-show:
55+
python -m pytest -vs -rs -p no:xdist -p no:randomly -p no:repeat -p no:cov -o log_cli=true --run-system-tests-show mantidimaging/gui/test/
56+
5457
test-screenshots:
5558
-mkdir ${TEST_RESULT_DIR}
5659
APPLITOOLS_API_KEY=local APPLITOOLS_IMAGE_DIR=${TEST_RESULT_DIR} ${XVFBRUN} pytest -p no:xdist -p no:randomly -p no:cov mantidimaging/eyes_tests/ -vs --run-eyes-tests

conftest.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX - License - Identifier: GPL-3.0-or-later
33
from __future__ import annotations
44

5+
import os
56
from collections import Counter
67

78
import pytest
@@ -12,7 +13,8 @@
1213

1314

1415
def pytest_addoption(parser):
15-
parser.addoption("--run-system-tests", action="store_true", default=False, help="Run GUI system tests")
16+
parser.addoption("--run-system-tests", action="store_true", default=False, help="Run GUI system tests offscreen")
17+
parser.addoption("--run-system-tests-show", action="store_true", default=False, help="Run GUI system tests")
1618
parser.addoption("--run-unit-tests", action="store_true", default=False, help="Run unit tests")
1719
parser.addoption("--run-eyes-tests", action="store_true", default=False, help="Run eyes tests")
1820

@@ -30,6 +32,10 @@ def pytest_configure(config):
3032
def pytest_collection_modifyitems(config, items):
3133
if config.getoption("--run-system-tests"):
3234
allowed_markers.append(pytest.mark.system.mark)
35+
os.environ["QT_QPA_PLATFORM"] = "minimal"
36+
if config.getoption("--run-system-tests-show"):
37+
allowed_markers.append(pytest.mark.system.mark)
38+
os.environ["QT_QPA_PLATFORM"] = ""
3339
if config.getoption("--run-eyes-tests"):
3440
allowed_markers.append(pytest.mark.eyes.mark)
3541
if config.getoption("--run-unit-tests") or len(allowed_markers) == 0:

mantidimaging/gui/test/gui_system_base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
import unittest
77
from unittest import mock
88

9+
from PyQt5 import QtCore
910
from PyQt5.QtCore import Qt, QTimer
1011
from PyQt5.QtTest import QTest
1112
from PyQt5.QtWidgets import QApplication, QMessageBox, QInputDialog, QDialog
1213
import pytest
14+
from mantidimaging.test_helpers.qt_test_message_handler import qt_message_handler
1315

1416
from mantidimaging.core.utility.leak_tracker import leak_tracker
1517
from mantidimaging.gui.windows.main import MainWindowView
@@ -24,6 +26,8 @@
2426
SHOW_DELAY = 10 # Can be increased to watch tests
2527
SHORT_DELAY = 100
2628

29+
QtCore.qInstallMessageHandler(qt_message_handler)
30+
2731

2832
@mock_versions
2933
@pytest.mark.system
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (C) 2021 ISIS Rutherford Appleton Laboratory UKRI
2+
# SPDX - License - Identifier: GPL-3.0-or-later
3+
from PyQt5 import QtCore
4+
5+
6+
def qt_message_handler(mode, context, message):
7+
mode_map = {
8+
QtCore.QtInfoMsg: 'INFO',
9+
QtCore.QtWarningMsg: 'WARNING',
10+
QtCore.QtCriticalMsg: 'CRITICAL',
11+
QtCore.QtFatalMsg: 'FATAL'
12+
}
13+
14+
# Get the string label for mode, otherwise default to 'DEBUG'
15+
mode_str = mode_map.get(mode, 'DEBUG')
16+
if mode == QtCore.QtWarningMsg and 'propagateSizeHints' in message:
17+
return
18+
print(f"qt_message_handler: line: {context.line}, func: {context.function}, file: {context.file}")
19+
print(f"{mode_str}: {message}\n")

0 commit comments

Comments
 (0)