Skip to content

refactor(tests): load-time sys.modules stubs that outlive the file that needed them #4803

Backlog

Description

@pavshulin

Summary

Three test files install a stub into sys.modules while they are being collected and never remove it. A fourth removes its stubs only after its own tests have run. Other files in the same process then import against the stub.

Context

Found while fixing #4620.

  • tests/git_sync/test_s5_conflict_classifier.py and tests/git_sync/test_s7_reserve_instance_id.py each install a database stub at load when none is present (in the first, db is None) and never remove it. In the live-tier selection the first one wins, and every module imported later binds db = None. This is what made seven tests of test_cb_probe_execution_close.py fail in the nightly (dev-nightly red: Tier 3 failed on dev #4620). The dev-nightly red: Tier 3 failed on dev #4620 work moves that module to tests/unit/, so nothing in the live selection depends on the stub any more, but the stub is still left behind.
  • tests/unit/test_web_file_upload.py and tests/unit/test_slack_file_uploads.py install a partial services.docker_utils stub (setdefault) at collection. The first never removes it; the second restores sys.modules once its own tests finish. In a two-file run with the first (in either order), or with the second when its tests run last, routers.internal cannot be imported and three tests of test_cb_probe_execution_close.py fail. A whole-suite collection does not show it, because the real module is imported first.
  • tests/conftest.py::stubbed_modules exists for this: install for the load, restore, and verify that nothing leaked.

Acceptance Criteria

  • The four files scope their stubs to the load that needs them.
  • Their lines leave tests/lint_sys_modules_baseline.txt.
  • test_cb_probe_execution_close.py passes in a two-file run with each of the two upload files, in both orders.

Activity

  1. added
    priority-p3
    type-refactor
    theme-devex
    on Nov 27, 2026
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

    priority-p3theme-devextype-refactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions