Skip to content

Commit 9d27ca3

Browse files
committed
Enhance DataLab test fixtures to handle CI environments gracefully
- Introduced a flag to track DataLab start failures in CI environments. - Updated the `auto_datalab` fixture to skip tests if DataLab cannot be started. - Added documentation to clarify the requirements for running tests with special characters in object names.
1 parent 0e486c1 commit 9d27ca3

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

datalab_kernel/tests/conftest.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ def datalab_instance(request):
304304
_lazy_datalab_started = False
305305

306306

307+
# Track if we've detected that DataLab cannot be started (CI environment)
308+
_datalab_start_failed = False
309+
310+
307311
@pytest.fixture(scope="session")
308312
def auto_datalab(request, datalab_instance): # pylint: disable=redefined-outer-name,unused-argument
309313
"""Lazy DataLab starter - starts DataLab when first live test runs.
@@ -312,16 +316,22 @@ def auto_datalab(request, datalab_instance): # pylint: disable=redefined-outer-
312316
It ensures DataLab is started only after standalone tests complete.
313317
314318
Also sets environment variables for WebAPI connection.
319+
320+
In CI environments (no display), skips tests gracefully instead of failing.
315321
"""
316-
global _lazy_datalab_started # pylint: disable=global-statement
322+
global _lazy_datalab_started, _datalab_start_failed # pylint: disable=global-statement
317323

318324
standalone_only = request.config.getoption("--standalone-only")
319325
explicit_start = request.config.getoption("--start-datalab")
320326
force_live = request.config.getoption("--live")
321327

322328
# Don't start if standalone-only mode
323329
if standalone_only:
324-
return
330+
pytest.skip("Live tests skipped in standalone-only mode")
331+
332+
# If we previously failed to start DataLab (e.g., CI environment), skip
333+
if _datalab_start_failed:
334+
pytest.skip("DataLab not available (previous start attempt failed)")
325335

326336
# Set environment variables for WebAPI connection
327337
# These are used by WebApiBackend to find the server
@@ -339,7 +349,14 @@ def auto_datalab(request, datalab_instance): # pylint: disable=redefined-outer-
339349
print("🚀 Starting DataLab for live tests...")
340350
print("=" * 70)
341351
if not _is_datalab_running():
342-
_start_datalab()
352+
try:
353+
_start_datalab()
354+
except RuntimeError as exc:
355+
# Failed to start DataLab - likely CI environment without display
356+
_datalab_start_failed = True
357+
pytest.skip(
358+
f"DataLab cannot be started (CI/headless environment?): {exc}"
359+
)
343360
# _start_datalab() already waits for WebAPI to be ready
344361
print("✅ DataLab ready for live tests")
345362
print("=" * 70 + "\n")

datalab_kernel/tests/test_webapi_backend.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,13 @@ def test_add_and_get_image(self, webapi_backend):
304304
webapi_backend.remove("webapi_test_image")
305305

306306

307+
@pytest.mark.webapi
308+
@pytest.mark.integration
307309
class TestWebApiBackendSpecialCharacters:
308-
"""Test handling of special characters in object names."""
310+
"""Test handling of special characters in object names.
311+
312+
These tests require DataLab with WebAPI running.
313+
"""
309314

310315
def test_url_encoding_special_chars(self, webapi_backend):
311316
"""Test that special characters in names are properly URL-encoded."""

0 commit comments

Comments
 (0)