python / python/cpython

test_lazy_import: add coverage for reload() and sys.modules deletion after reification

Open
#149,013 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

3.15 tests topic-lazy-imports type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report / test coverage gap

Lib/test/test_lazy_import/__init__.py has broad lazy import coverage, but it misses two practical state-transition scenarios after reification:

  1. importlib.reload() on a module that was first imported lazily and then reified.
  2. Deleting sys.modules[name] after reification and then importing again.

Why this matters

These are common import-state operations and can regress subtly when lazy import behavior changes.
Adding tests helps lock in expected semantics and prevents regressions in future import machinery refactors.

Proposed change

Add two tests in test_lazy_import:

  • test_reload_after_lazy_reification_keeps_single_module_object

    • Reify a lazily imported module.
    • Call importlib.reload().
    • Assert identity consistency between the binding and sys.modules[name].
  • test_reimport_after_deleting_sys_modules_entry_creates_new_module

    • Reify a lazily imported module.
    • Delete sys.modules[name].
    • Verify old binding still works.
    • Re-import module and assert a new module object is cached.

Affected files

  • Lib/test/test_lazy_import/__init__.py

Version

  • main (3.15 development branch)

Additional notes

This is test-only; no runtime behavior change is introduced.

Linked PRs
  • gh-149014

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Lib/test/test_lazy_import/init.py and read the existing lazy-import coverage and related helpers. Run the test_lazy_import tests first, then add coverage for reload() after reification and re-import after deleting sys.modules[name]. Done means the binding and cached module retain the stated identity behavior, while the deleted-entry re-import creates a new cached module.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.