Skip to content

tests/cli/test_main.py leaves hand-written sys.modules stand-ins behind: 10 errors when paired with test_public_api #688

Description

@JarryShaw

tests/cli/test_main.py writes to sys.modules by hand and never restores, so pairing it with tests/project/test_public_api.py produces 10 errors. Measured identically on origin/main and on #686's branch, so it is neither caused nor cured by that change.

The shape

Same class of defect as #674: a test binds stand-ins into the pcapkit region of sys.modules and leaves them there, so a later test that introspects the real package gets the stand-ins. #674's fix (#686) covers the loaders in tests/_support.py; this file bypasses them entirely with its own writes, so it is untouched by that work.

Why it is normally invisible

The same masking as #674: tests/conftest.py:95's autouse restore_module_table fixture repairs the region after every test, so the symptom does not appear under a normal pytest run. It surfaces under --noconftest, under the stdlib unittest runner, or any route that does not load that conftest.

Worth noting that tests/conftest.py names this very file as the witness for #662's guard — so the guard is documented against the file that still needs the underlying fix.

Suggested direction

Route its sys.modules writes through the restoring helpers tests/_support.py now provides (restore_modules_after, or isolate_modules) rather than hand-rolling them, so the restoration is owed and discharged in one place. A regression assertion that the pcapkit region is unchanged after the module's tests would pin it.

Provenance

Found by #686's worker while auditing leakage for #674 and deliberately left out of that PR — different file, different mechanism, and fixing it there would have widened a test-infrastructure change into the CLI tests. The 10-error measurement is its figure; I have not independently re-run it.

Activity

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

    testPull requests that add or correct tests (test: subject prefix)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions