Skip to content

Commit 9c88dda

Browse files
committed
pytest: switch to offscreen mode
1 parent 30d79f2 commit 9c88dda

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

qwt/tests/conftest.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,28 @@
1313
os.environ[TestEnvironment.UNATTENDED_ENV] = "1"
1414

1515

16+
def pytest_addoption(parser):
17+
"""Add custom command line options to pytest."""
18+
# See this StackOverflow answer for more information: https://t.ly/9anqz
19+
parser.addoption(
20+
"--repeat", action="store", help="Number of times to repeat each test"
21+
)
22+
parser.addoption(
23+
"--show-windows",
24+
action="store_true",
25+
default=False,
26+
help="Display Qt windows during tests (disables QT_QPA_PLATFORM=offscreen)",
27+
)
28+
29+
30+
def pytest_configure(config):
31+
"""Configure pytest based on command line options."""
32+
if config.option.durations is None:
33+
config.option.durations = 10 # Default to showing 10 slowest tests
34+
if not config.getoption("--show-windows"):
35+
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
36+
37+
1638
def pytest_report_header(config):
1739
"""Add additional information to the pytest report header."""
1840
qtbindings_version = qtpy.PYSIDE_VERSION
@@ -24,14 +46,6 @@ def pytest_report_header(config):
2446
]
2547

2648

27-
def pytest_addoption(parser):
28-
"""Add custom command line options to pytest."""
29-
# See this StackOverflow answer for more information: https://t.ly/9anqz
30-
parser.addoption(
31-
"--repeat", action="store", help="Number of times to repeat each test"
32-
)
33-
34-
3549
def pytest_generate_tests(metafunc):
3650
"""Generate tests for the given metafunc."""
3751
# See this StackOverflow answer for more information: https://t.ly/9anqz

0 commit comments

Comments
 (0)