Skip to content

Commit 87a52dc

Browse files
committed
Add display requirement marker for tests needing a GUI and update relevant tests
1 parent 9b3b334 commit 87a52dc

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

plotpy/tests/conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,22 @@ def pytest_addoption(parser):
3333

3434
def pytest_configure(config):
3535
"""Configure pytest based on command line options."""
36+
config.addinivalue_line(
37+
"markers",
38+
"requires_display: mark test as requiring a display "
39+
"(skipped in offscreen mode)",
40+
)
3641
if not config.getoption("--show-windows"):
3742
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
3843

3944

45+
def pytest_runtest_setup(item):
46+
"""Run setup before each test."""
47+
if "requires_display" in item.keywords:
48+
if os.environ.get("QT_QPA_PLATFORM") == "offscreen":
49+
pytest.skip("Skipped in offscreen mode (requires display)")
50+
51+
4052
@pytest.fixture(scope="session", autouse=True)
4153
def disable_gc_for_tests():
4254
"""Disable garbage collection for all tests in the session."""

plotpy/tests/unit/test_manipulate_selection.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import os
43
from typing import TYPE_CHECKING, Callable, TypeVar
54

65
import numpy as np
@@ -269,7 +268,7 @@ def test_select_all_items():
269268
exec_dialog(win)
270269

271270

272-
@pytest.mark.skipif(os.name != "nt", reason="Only tested on Windows.")
271+
@pytest.mark.requires_display
273272
def test_rotate_with_mouse():
274273
"""Test rotating an image item with the mouse."""
275274
with qt_app_context(exec_loop=False):
@@ -320,7 +319,7 @@ def test_rectangular_selection():
320319
exec_dialog(win)
321320

322321

323-
@pytest.mark.skipif(os.name != "nt", reason="Only tested on Windows.")
322+
@pytest.mark.requires_display
324323
@pytest.mark.parametrize(
325324
"mouse_path, rotation",
326325
[

0 commit comments

Comments
 (0)