Skip to content

Studio backend tests: the non-package loggers stub breaks collection when pytest runs from the repo root #10995

Closed

Description

@danielhanchen

Summary

83 files under studio/backend/tests/ register a non-package stub for loggers at import time:

# Mirror test_preview.py: the real `loggers` package pulls in heavy handlers.
_loggers_stub = _types.ModuleType("loggers")
_loggers_stub.get_logger = lambda name: __import__("logging").getLogger(name)
sys.modules.setdefault("loggers", _loggers_stub)

ModuleType("loggers") has no __path__, so it is a module and not a package. Once it is in sys.modules, any later from loggers.media_progress import ... in the same process fails with

ModuleNotFoundError: No module named 'loggers.media_progress'; 'loggers' is not a package

studio/backend/routes/inference.py:57 does exactly that import, so every test module that reaches routes.inference after one of those 83 files has been collected errors out at collection.

Why it is usually invisible

.github/workflows/studio-backend-ci.yml runs with working-directory: studio/backend, and in that layout the real loggers package is imported before any stub lands, so setdefault is a no-op and everything works. The breakage only shows when pytest is invoked from the repo root with PYTHONPATH=studio/backend, which is how out-of-tree runners tend to call it.

Reproduction, on unmodified main

$ cd <repo root>
$ PYTHONPATH=studio/backend python -m pytest \
    studio/backend/tests/test_preview_routes.py \
    studio/backend/tests/test_video_attachment_part.py \
    studio/backend/tests/test_video_pr9057_simulation.py -q

ERROR studio/backend/tests/test_preview_routes.py
ERROR studio/backend/tests/test_video_attachment_part.py
ERROR studio/backend/tests/test_video_pr9057_simulation.py
!!! Interrupted: 3 errors during collection !!!

test_preview_routes.py sorts first, so its stub poisons the rest of the session. Each of those files passes on its own.

This reproduces on Linux, and it is what made the Linux, Windows and Apple Silicon legs of a cross-platform staging run for #10439 fail identically. Nothing in that PR is involved: the same three files fail the same way on a clean main checkout.

Suggested fix

One place rather than 83. Either give the stub a package shape and register the submodule it is expected to carry, or have studio/backend/tests/conftest.py settle loggers before any test module is imported, so setdefault in the individual files stays the no-op it already is under the repo's own CI. The second keeps the "avoid heavy handlers" intent that the comment in those files is protecting.

Why it is worth fixing

It makes the backend suite depend on the working directory it is launched from, and it silently blocks any runner that invokes pytest from the repo root, which is the natural way to run a subset of test files cross-platform.

Activity

  1. debojyoti-dev commented on Sep 15, 2026

    @debojyoti-dev
    Contributor

    I’d like to take this issue up.

    I’ll investigate the test import/collection flow and the interaction between the loggers stub, sys.modules, and Python’s package resolution. The core issue appears to be that the test-level ModuleType("loggers") stub is registered without a __path__, causing Python to treat loggers as a regular module and preventing subsequent imports such as loggers.media_progress from resolving.

    I’ll reproduce the failure from the repository root using the reported PYTHONPATH=studio/backend setup, verify that the issue is independent of #10439, and confirm that the affected tests still pass when executed individually.

    For the fix, I’ll evaluate centralizing the stub initialization in studio/backend/tests/conftest.py so the real/stubbed loggers module is established before test collection, while preserving the existing intent of avoiding the heavy logger handlers. I’ll also check whether this can be done without introducing ordering-dependent behavior or affecting the repository's existing CI invocation.

    Once implemented, I’ll run the affected subset from both the repository root and studio/backend, along with the relevant backend test suite, to verify that collection and import behavior are consistent across invocation environments.

  2. debojyoti-dev commented on Sep 15, 2026

    @debojyoti-dev
    Contributor

    @danielhanchen @codex review my PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions