Skip to content

gh-156570: handle lazy warnings import in test helper - #156573

Open
mikemikimike wants to merge 4 commits into
python:mainfrom
mikemikimike:fix/warnings-helper-lazy-imports
Open

gh-156570: handle lazy warnings import in test helper#156573
mikemikimike wants to merge 4 commits into
python:mainfrom
mikemikimike:fix/warnings-helper-lazy-imports

Conversation

@mikemikimike

@mikemikimike mikemikimike commented Aug 29, 2026

Copy link
Copy Markdown

Issue: #156570

Summary

warnings_helper._filterwarnings() indexed sys.modules['warnings'] directly. Under -X lazy_imports=all, evaluating the module-level import can leave that entry unresolved, causing check_warnings() to raise KeyError.

Use the already imported module as a fallback when the warnings entry is absent, and add regression coverage for this state.

Testing

  • python Lib/test/test_warnings_helper.py
  • python -m py_compile Lib/test/support/warnings_helper.py Lib/test/test_warnings_helper.py
  • git diff --check

Compatibility

The change preserves the existing module replacement behavior used by test_warnings while avoiding a KeyError when lazy imports have not populated sys.modules.

AI assistance was used to identify the issue and prepare this patch.

@python-cla-bot

python-cla-bot Bot commented Aug 29, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app

bedevere-app Bot commented Aug 29, 2026

Copy link
Copy Markdown

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 skip news label instead.

@bedevere-app

bedevere-app Bot commented Aug 29, 2026

Copy link
Copy Markdown

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 skip news label instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant