Repository navigation
Keep the loggers stub a package so tests/studio can be collected in one process - #10531
Merged
Merged
Conversation
…ne process
tests/studio/load_freeze/test_load_orchestrator.py installs a ModuleType("loggers") stub into
sys.modules at import time. That entry outlives the module, and pytest imports every test
module during collection, so any later test reaching a real submodule died at COLLECTION:
ModuleNotFoundError: No module named 'loggers.media_progress'; 'loggers' is not a package
which reads like a missing dependency rather than one file shadowing a package for the whole
session. It took tests/studio/test_mlx_context_platform_matrix.py with it, so the directory
could not be collected in one pytest process at all: 8331 collected + 1 error, and the file
passes its own 60 tests when run alone.
The stub itself is reasonable -- it avoids pulling structlog and the rest of the chain in for a
test that only needs get_logger. It just has to stay a PACKAGE, so __path__ now points at the
real studio/backend/loggers, which the sys.path insert two lines above already reaches.
Submodule imports resolve to the real files and get_logger stays the cheap stub.
This is the same hazard the structlog block immediately below already guards against, in a
comment that spells it out: "a bare setdefault would shadow the real package". The care was
applied to structlog and not to loggers. From #5669; not a recent regression.
tests/studio/test_loggers_package_not_shadowed.py asserts the invariant at RUN time, after
collection has installed every module-level stub in the session. Verified by mutation: drop
the __path__ line and both its tests fail; restore it and they pass.
79 other test files use the same stub pattern without __path__. They are left alone: they sit
in sessions where nothing imports a real loggers submodule, studio/backend/tests and
tests/python both collect clean, and rewriting them would be churn for no defect.
tests/studio + tests/python now run as one process: 10595 passed, 333 skipped.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
pre-commit-ci
Bot
requested review from
LeoBorcherding and
oobabooga
as code owners
September 8, 2026 17:03
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
tests/studiocannot be collected in a single pytest process on main:That file passes its own 60 tests when run alone, so the failure is entirely about what else is in the session.
Cause
tests/studio/load_freeze/test_load_orchestrator.pyinstalls a stub at import time:pytest imports every test module during collection, and that
sys.modulesentry outlives the module that installed it. A stub built byModuleTypehas no__path__, so from that point on everyloggers.<submodule>import in the session fails, and it fails as'loggers' is not a package-- which reads like a missing dependency rather than one test file shadowing a package.Not a recent regression: this arrived with #5669. Worth noting that the structlog block immediately below it already guards against this exact hazard, in a comment that says so:
# structlog is a hard studio.txt requirement imported only lazily, so a bare setdefault would shadow the real package.The care was applied to structlog and not to
loggers.Fix
The stub itself is reasonable -- it exists so this file need not import structlog and the rest of the logging chain for the one
get_loggerit uses. It just has to remain a package:_STUDIO_BACKENDis already onsys.pathtwo lines above, so submodule imports resolve to the real files whileget_loggerstays the cheap stub.Guard
tests/studio/test_loggers_package_not_shadowed.pyasserts the invariant at run time, which is the point: collection has finished by then, so every module-level stub in the session is already installed. It checks both that the entry is a package and that a real submodule imports through it.Verified by mutation: drop the
__path__line and both tests fail; restore it and they pass.Scope
79 other test files use the same stub pattern without
__path__. Left alone deliberately -- they sit in sessions where nothing imports a realloggerssubmodule,studio/backend/testsandtests/pythonboth collect clean, and rewriting them would be churn against no defect. If one of those sessions later grows a test that needs the real package, this guard is what will say so.Verification
tests/studiocollection: 8331 + 1 error -> 8407 collected, no errors.tests/studio tests/python studio/backend/tests/test_torchao_select.pyas one process: 10595 passed, 333 skipped, 0 failed.tests/studio/load_freezeon its own: 23 passed, unchanged.ruff check tests: clean.