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).
This commit is contained in:
@@ -1,11 +1,18 @@
|
|||||||
"""Tests for API endpoints (public + authenticated)."""
|
"""Tests for API endpoints (public + authenticated)."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import pytest
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
|
|
||||||
from wled_controller.main import app
|
from wled_controller.main import app
|
||||||
from wled_controller import __version__
|
from wled_controller import __version__
|
||||||
from wled_controller.config import get_config
|
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)
|
client = TestClient(app)
|
||||||
|
|
||||||
# Build auth header from the first configured API key
|
# Build auth header from the first configured API key
|
||||||
@@ -41,8 +48,9 @@ def test_version_endpoint():
|
|||||||
assert data["api_version"] == "v1"
|
assert data["api_version"] == "v1"
|
||||||
|
|
||||||
|
|
||||||
|
@requires_display
|
||||||
def test_get_displays():
|
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)
|
response = client.get("/api/v1/config/displays", headers=AUTH_HEADERS)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
data = response.json()
|
data = response.json()
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
"""Tests for screen capture functionality."""
|
"""Tests for screen capture functionality."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@@ -14,7 +17,12 @@ from wled_controller.core.capture.screen_capture import (
|
|||||||
ScreenCapture,
|
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():
|
def test_get_available_displays():
|
||||||
"""Test getting available displays."""
|
"""Test getting available displays."""
|
||||||
displays = get_available_displays()
|
displays = get_available_displays()
|
||||||
@@ -32,6 +40,7 @@ def test_get_available_displays():
|
|||||||
assert display.height > 0
|
assert display.height > 0
|
||||||
|
|
||||||
|
|
||||||
|
@requires_display
|
||||||
def test_capture_display():
|
def test_capture_display():
|
||||||
"""Test capturing a display."""
|
"""Test capturing a display."""
|
||||||
# Capture the first display
|
# Capture the first display
|
||||||
@@ -46,6 +55,7 @@ def test_capture_display():
|
|||||||
assert capture.image.shape == (capture.height, capture.width, 3)
|
assert capture.image.shape == (capture.height, capture.width, 3)
|
||||||
|
|
||||||
|
|
||||||
|
@requires_display
|
||||||
def test_capture_display_invalid_index():
|
def test_capture_display_invalid_index():
|
||||||
"""Test capturing with invalid display index."""
|
"""Test capturing with invalid display index."""
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
@@ -197,6 +207,7 @@ def test_calculate_color_empty_pixels():
|
|||||||
assert calculate_dominant_color(empty_pixels) == (0, 0, 0)
|
assert calculate_dominant_color(empty_pixels) == (0, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
|
@requires_display
|
||||||
def test_end_to_end_screen_capture():
|
def test_end_to_end_screen_capture():
|
||||||
"""Test complete screen capture workflow."""
|
"""Test complete screen capture workflow."""
|
||||||
# Get available displays
|
# Get available displays
|
||||||
|
|||||||
Reference in New Issue
Block a user