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.

Keep the loggers stub a package so tests/studio can be collected in one process (#10531)

Daniel Han62da4f0d2aa8
diff --git a/tests/studio/load_freeze/test_load_orchestrator.py b/tests/studio/load_freeze/test_load_orchestrator.py
index fa343cd5c0c..f654c99e60d 100644
--- a/tests/studio/load_freeze/test_load_orchestrator.py
+++ b/tests/studio/load_freeze/test_load_orchestrator.py
@@ -46,7 +46,12 @@ sys.path.insert(0, str(Path(__file__).resolve().parent))
import logging as _logging # noqa: E402
+# Stub get_logger so this file need not import the real package's structlog chain, but keep
+# __path__ pointing at the real package: this entry outlives the module in sys.modules, and a
+# stub with no __path__ makes every later-collected test that reaches loggers.media_progress
+# die with "'loggers' is not a package". Same care the structlog block below already takes.
_loggers_stub = types.ModuleType("loggers")
+_loggers_stub.__path__ = [str(_STUDIO_BACKEND / "loggers")]
_loggers_stub.get_logger = lambda name: _logging.getLogger(name)
sys.modules.setdefault("loggers", _loggers_stub)
# structlog is a hard studio.txt requirement imported only lazily, so a bare setdefault would shadow the real package.
diff --git a/tests/studio/test_loggers_package_not_shadowed.py b/tests/studio/test_loggers_package_not_shadowed.py
new file mode 100644
index 00000000000..2621aa04ff5
--- /dev/null
+++ b/tests/studio/test_loggers_package_not_shadowed.py
@@ -0,0 +1,42 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+"""`loggers` must still be a PACKAGE after every test module has been imported.
+
+Test modules that exercise a single backend file routinely stub `loggers` so they need
+not pull structlog and the rest of the chain in. The stub is fine; leaving a stub with no
+`__path__` in `sys.modules` is not, because that entry outlives the module that installed
+it and pytest imports every test module during collection. Any later test that reaches a
+real submodule then dies at COLLECTION with
+
+ ModuleNotFoundError: No module named 'loggers.media_progress'; 'loggers' is not a package
+
+which reads like a missing dependency rather than one test file shadowing a package for
+the whole session. tests/studio/load_freeze/test_load_orchestrator.py did exactly this
+(from #5669) and took tests/studio/test_mlx_context_platform_matrix.py down with it, so
+the whole directory could not be collected in one pytest process.
+
+Asserting this at RUN time is what makes it a guard: collection has finished by then, so
+every module-level stub in the session is already installed.
+"""
+
+import importlib
+import sys
+
+
+def test_the_loggers_entry_left_in_sys_modules_is_still_a_package():
+ loggers = sys.modules.get("loggers")
+ if loggers is None:
+ return # nothing in this session touched it, so nothing can have shadowed it
+ assert hasattr(loggers, "__path__"), (
+ "a test module replaced `loggers` with a non-package stub and left it in "
+ "sys.modules; give the stub __path__ = [<studio/backend/loggers>] so submodule "
+ "imports still resolve"
+ )
+
+
+def test_a_real_submodule_still_imports_through_whatever_stub_is_installed():
+ """__path__ is only worth asserting if it actually reaches the real files."""
+ if sys.modules.get("loggers") is None:
+ return
+ assert importlib.import_module("loggers.media_progress") is not None