Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio backend tests: settle the real loggers package in conftest for repo-root pytest runs (#11028)

jishnav48b08317a24a
diff --git a/studio/backend/tests/conftest.py b/studio/backend/tests/conftest.py
index 488691e20bd..24d5fa81f20 100644
--- a/studio/backend/tests/conftest.py
+++ b/studio/backend/tests/conftest.py
@@ -42,6 +42,25 @@ _backend_root = Path(__file__).resolve().parent.parent
if str(_backend_root) not in sys.path:
sys.path.insert(0, str(_backend_root))
+# Settle the real ``loggers`` package before any test module is imported. 84 test files
+# stub it with a bare ``ModuleType``, which has no ``__path__`` and so is not a package: once
+# one wins the slot, ``from loggers.media_progress import ...`` (routes/inference.py, at module
+# level) dies with "'loggers' is not a package". Only bites when pytest is invoked from the
+# repo root, which is why the repo's own CI, run from studio/backend, never saw it.
+try:
+ import loggers # noqa: E402
+except ImportError:
+ # loggers.handlers needs structlog, and some tests stub structlog to run without it. Where
+ # it is missing, the import this protects would die on structlog anyway.
+ pass
+else:
+ # A stub satisfies the import too: ``__path__`` is the whole difference. Also keeps the
+ # name used, which is what verify_import_hoist.py reads a module-level import for.
+ assert hasattr(loggers, "__path__"), (
+ f"the 'loggers' slot holds a non-package ({loggers!r}); a ModuleType stub from some "
+ "test module got there first, so `from loggers.media_progress import ...` will fail"
+ )
+
# tests/_shared, as tests/conftest.py does for its own trees. Module scope, not a fixture:
# a test module imports from it at collection, before any fixture runs.
for _up in Path(__file__).resolve().parents: