gh-156570: handle lazy warnings import in test helper - #156573
gh-156570: handle lazy warnings import in test helper#156573mikemikimike wants to merge 5 commits into
Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
There was a problem hiding this comment.
Why a new file instead of adding it to test_support?
|
Thanks for the review. I moved the regression test into the existing |
Issue: #156570
Summary
warnings_helper._filterwarnings()indexedsys.modules['warnings']directly. Under-X lazy_imports=all, evaluating the module-level import can leave that entry unresolved, causingcheck_warnings()to raiseKeyError.Use the already imported module as a fallback when the
warningsentry is absent, and add regression coverage for this state.Testing
python Lib/test/test_warnings_helper.pypython -m py_compile Lib/test/support/warnings_helper.py Lib/test/test_warnings_helper.pygit diff --checkCompatibility
The change preserves the existing module replacement behavior used by
test_warningswhile avoiding aKeyErrorwhen lazy imports have not populatedsys.modules.AI assistance was used to identify the issue and prepare this patch.