From eeb51fa4e7c6473d55e36d93708157335b4251f3 Mon Sep 17 00:00:00 2001 From: "alexei.dolgolyov" Date: Sun, 22 Mar 2026 02:27:04 +0300 Subject: [PATCH] fix: skip display-dependent tests on headless CI Tests that call get_available_displays() or capture_display() require a real display ($DISPLAY on Linux, always available on Windows/macOS). Mark them with @requires_display to skip on headless CI instead of failing with "$DISPLAY not set". Affects: test_screen_capture.py (4 tests), test_api.py (1 test). --- server/tests/test_api.py | 10 +++++++++- server/tests/test_screen_capture.py | 11 +++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/server/tests/test_api.py b/server/tests/test_api.py index e3729bd..bc0e564 100644 --- a/server/tests/test_api.py +++ b/server/tests/test_api.py @@ -1,11 +1,18 @@ """Tests for API endpoints (public + authenticated).""" +import os +import sys + +import pytest from fastapi.testclient import TestClient from wled_controller.main import app from wled_controller import __version__ from wled_controller.config import get_config +_has_display = bool(os.environ.get("DISPLAY") or sys.platform == "win32" or sys.platform == "darwin") +requires_display = pytest.mark.skipif(not _has_display, reason="No display available (headless CI)") + client = TestClient(app) # Build auth header from the first configured API key @@ -41,8 +48,9 @@ def test_version_endpoint(): assert data["api_version"] == "v1" +@requires_display def test_get_displays(): - """Test get displays endpoint (requires auth).""" + """Test get displays endpoint (requires auth and a real display).""" response = client.get("/api/v1/config/displays", headers=AUTH_HEADERS) assert response.status_code == 200 data = response.json() diff --git a/server/tests/test_screen_capture.py b/server/tests/test_screen_capture.py index 11b1ca5..0bf2791 100644 --- a/server/tests/test_screen_capture.py +++ b/server/tests/test_screen_capture.py @@ -1,5 +1,8 @@ """Tests for screen capture functionality.""" +import os +import sys + import numpy as np import pytest @@ -14,7 +17,12 @@ from wled_controller.core.capture.screen_capture import ( ScreenCapture, ) +# Skip tests that require a real display on headless CI +_has_display = bool(os.environ.get("DISPLAY") or sys.platform == "win32" or sys.platform == "darwin") +requires_display = pytest.mark.skipif(not _has_display, reason="No display available (headless CI)") + +@requires_display def test_get_available_displays(): """Test getting available displays.""" displays = get_available_displays() @@ -32,6 +40,7 @@ def test_get_available_displays(): assert display.height > 0 +@requires_display def test_capture_display(): """Test capturing a display.""" # Capture the first display @@ -46,6 +55,7 @@ def test_capture_display(): assert capture.image.shape == (capture.height, capture.width, 3) +@requires_display def test_capture_display_invalid_index(): """Test capturing with invalid display index.""" with pytest.raises(ValueError): @@ -197,6 +207,7 @@ def test_calculate_color_empty_pixels(): assert calculate_dominant_color(empty_pixels) == (0, 0, 0) +@requires_display def test_end_to_end_screen_capture(): """Test complete screen capture workflow.""" # Get available displays