test_lazy_import: add coverage for reload() and sys.modules deletion after reification
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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:
importlib.reload()on a module that was first imported lazily and then reified.- 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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia in Lib/test/test_lazy_import/init.py e leggi la copertura esistente per i lazy-import e gli helper correlati. Esegui prima i test test_lazy_import, poi aggiungi la copertura per reload() dopo la reificazione e per il re-import dopo l’eliminazione di sys.modules[name]. Il lavoro è completo quando il binding e il modulo memorizzato nella cache mantengono il comportamento di identità indicato, mentre il re-import dopo l’eliminazione della voce crea un nuovo modulo memorizzato nella cache.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- testing-qa
- Tipo di issue
- Bug
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 35/100