Skip to content

Commit 77c08bf

Browse files
committed
attempt napari tests with offscreen
1 parent 0cbb9f3 commit 77c08bf

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

tests/conftest.py

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

3+
import os
34
import random
45
import string
56
from abc import ABC, ABCMeta
@@ -24,6 +25,8 @@
2425

2526
from napari_spatialdata.utils._test_utils import export_figure, save_image
2627

28+
OFFSCREEN = os.environ.get('QT_QPA_PLATFORM', '') == 'offscreen'
29+
2730
HERE: Path = Path(__file__).parent
2831

2932
SEED = 42

tests/test_interactive.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
from spatialdata.models import Image2DModel
1212

1313
from napari_spatialdata._interactive import Interactive
14-
from tests.conftest import PlotTester, PlotTesterMeta
14+
from tests.conftest import PlotTester, PlotTesterMeta, OFFSCREEN
1515

1616
ARM_PROBLEM = (
1717
parse_version(version("numpy")) < parse_version("2") and sys.platform == "darwin" and platform.machine() == "arm64"
1818
)
1919

2020

21+
@pytest.mark.skipif(not OFFSCREEN, reason="Not running in offscreen mode")
2122
@pytest.mark.usefixtures("mock_app_model")
2223
class TestImages(PlotTester, metaclass=PlotTesterMeta):
2324
def test_plot_can_add_element_image(self, sdata_blobs: SpatialData):
@@ -52,6 +53,7 @@ def test_switch_coordinate_system(self, sdata_blobs: SpatialData):
5253
Viewer.close_all()
5354

5455

56+
@pytest.mark.skipif(not OFFSCREEN, reason="Not running in offscreen mode")
5557
@pytest.mark.usefixtures("mock_app_model")
5658
def test_plot_can_add_element_switch_cs(sdata_blobs: SpatialData):
5759
i = Interactive(sdata=sdata_blobs, headless=True)
@@ -61,6 +63,7 @@ def test_plot_can_add_element_switch_cs(sdata_blobs: SpatialData):
6163
Viewer.close_all()
6264

6365

66+
@pytest.mark.skipif(not OFFSCREEN, reason="Not running in offscreen mode")
6467
@pytest.mark.usefixtures("mock_app_model")
6568
class TestInteractive(PlotTester, metaclass=PlotTesterMeta):
6669
def test_get_layer_existing(self, sdata_blobs: SpatialData):
@@ -91,6 +94,7 @@ def test_add_text_to_polygons(self, sdata_blobs: SpatialData):
9194
Viewer.close_all()
9295

9396

97+
@pytest.mark.skipif(not OFFSCREEN, reason="Not running in offscreen mode")
9498
@pytest.mark.skipif(ARM_PROBLEM, reason="Test will segfault on ARM with numpy < 2")
9599
@pytest.mark.use_thread_loader
96100
def test_load_data_in_thread(make_napari_viewer: Callable[[], Viewer], sdata_blobs: SpatialData, qtbot: QtBot) -> None:

tests/test_spatialdata.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from napari_spatialdata._sdata_widgets import CoordinateSystemWidget, ElementWidget, SdataWidget
2525
from napari_spatialdata.constants import config
2626
from napari_spatialdata.utils._test_utils import click_list_widget_item, get_center_pos_listitem
27+
from tests.conftest import OFFSCREEN
2728

2829
RNG = np.random.default_rng(seed=0)
2930

@@ -94,6 +95,7 @@ def test_sdatawidget_labels(qtbot, make_napari_viewer: Any, blobs_extra_cs: Spat
9495
assert widget.viewer_model.viewer.layers[0].metadata.get("region_key") is not None
9596

9697

98+
@pytest.mark.skipif(not OFFSCREEN, reason="Not running in offscreen mode")
9799
def test_sdatawidget_points(caplog, make_napari_viewer: Any, blobs_extra_cs: SpatialData):
98100
config.POINT_THRESHOLD = 400
99101
blobs_extra_cs.points["many_points"] = PointsModel.parse(

tests/test_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
_position_cluster_labels,
1616
_set_palette,
1717
)
18+
from tests.conftest import OFFSCREEN
1819

1920

2021
def test_get_categorical(adata_labels: AnnData):
@@ -84,6 +85,7 @@ def test_min_max_norm(vec: np.ndarray) -> None:
8485
assert (out.min(), out.max()) == (0, 1)
8586

8687

88+
@pytest.mark.skipif(not OFFSCREEN, reason="Not running in offscreen mode")
8789
def test_logger(caplog, prepare_continuous_test_data, adata_labels: AnnData, make_napari_viewer: Any):
8890
from napari_spatialdata._model import DataModel
8991
from napari_spatialdata._scatterwidgets import PlotWidget

0 commit comments

Comments
 (0)