René's URL Explorer Experiment


Title: test.support.warnings_helper.check_warnings() raises KeyError: 'warnings' under -X lazy_imports=all · Issue #156570 · python/cpython · GitHub

Open Graph Title: test.support.warnings_helper.check_warnings() raises KeyError: 'warnings' under -X lazy_imports=all · Issue #156570 · python/cpython

X Title: test.support.warnings_helper.check_warnings() raises KeyError: 'warnings' under -X lazy_imports=all · Issue #156570 · python/cpython

Description: Bug report test.support.warnings_helper.check_warnings() raises KeyError: 'warnings' under -X lazy_imports=all, taking down every test that uses it. Reproducer: ./python -X lazy_imports=all -m test test_sundry test_time Lib/test/support/...

Open Graph Description: Bug report test.support.warnings_helper.check_warnings() raises KeyError: 'warnings' under -X lazy_imports=all, taking down every test that uses it. Reproducer: ./python -X lazy_imports=all -m test...

X Description: Bug report test.support.warnings_helper.check_warnings() raises KeyError: 'warnings' under -X lazy_imports=all, taking down every test that uses it. Reproducer: ./python -X lazy_imports=all...

Opengraph URL: https://github.com/python/cpython/issues/156570

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"test.support.warnings_helper.check_warnings() raises KeyError: 'warnings' under -X lazy_imports=all","articleBody":"# Bug report\n\n`test.support.warnings_helper.check_warnings()` raises `KeyError: 'warnings'`\nunder `-X lazy_imports=all`, taking down every test that uses it.\n\nReproducer:\n\n    ./python -X lazy_imports=all -m test test_sundry test_time\n\n`Lib/test/support/warnings_helper.py:176`:\n\n    # Because test_warnings swap the module, we need to look up in the\n    # sys.modules dictionary.\n    wmod = sys.modules['warnings']\n\n`warnings` is not in `sys.modules` at interpreter startup, with or without lazy\nimports, so that key is populated solely by the module-level `import warnings`\nat the top of this same file. Reading the module out of `sys.modules` by\nsubscript means the global name is never touched, so under lazy imports the\nimport is never resolved and the key is never created.\n\n41 files under `Lib/test/` use `check_warnings()` / `check_no_warnings()`.\n\nOne-line fix — the default argument is evaluated on every call, which resolves\nthe lazy import before the lookup, and the module swap done by `test_warnings`\nstill wins:\n\n    wmod = sys.modules.get('warnings', warnings)\n\nVerified on `main` (d9154924138): with that change `test_sundry`, `test_time`\nand `test_warnings` pass under `-X lazy_imports=all`; `test___all__`,\n`test_sundry`, `test_time`, `test_warnings` and `test_support` still pass\nwithout the flag.\n\n`test_sundry` and `test_time` are not in the exclusion list proposed in\nGH-151105, so this is a failure mode the planned CI would not have covered.\n\nThe same pattern appears in the tests themselves. After the helper is fixed,\n`test___all__` still fails at `Lib/test/test___all__.py:49`:\n\n    if not hasattr(sys.modules[modname], \"__all__\"):\n\nwith `KeyError: '_osx_support'` — the module is imported by\n`exec(\"import %s\" % modname)` a few lines above, which under lazy imports\nleaves `sys.modules` untouched. Lines 71 and 76 do the same thing.\n\n`grep -rn 'sys\\.modules\\[' Lib/test/` reports 126 subscript reads. Most are\nlegitimate identity checks after an eager import; the ones worth auditing are\nthose where the key is expected to be filled by an import in the same file, or\nby an `exec`ed import statement.\n\nRelated to #149640.\n\n### CPython versions tested on:\n\nCPython main branch (d9154924138)\n\n### Operating systems tested on:\n\nLinux\n\n---\n\n🤖 Investigated and drafted with [Claude Code](https://claude.com/claude-code),\nmodel Claude Opus 5 (1M context).\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-156573\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/ashm-dev","@type":"Person","name":"ashm-dev"},"datePublished":"2026-08-29T12:01:47Z","url":"https://github.com/python/cpython/issues/156570"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:af56e59a-8a2d-1350-d7d1-9d11ecf25618
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8588:3B07B3:1D9346:2559F9:6B01F255
html-safe-noncee57ef352e2e95f49d19dbd5746cf192836a10177791d31f3ecfc293d59210630
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NTg4OjNCMDdCMzoxRDkzNDY6MjU1OUY5OjZCMDFGMjU1IiwidmlzaXRvcl9pZCI6IjgzNzU4ODY1ODI1MjAxODI2MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacfe433fd7469dcdb0a0abc2eb13e842f10d96142d652312795d464ef48951adc2
hovercard-subject-tagissue:5286419305
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/156570/issue_layout
twitter:imagehttps://opengraph.githubassets.com/107ab9977c4d4393c266ef33b7f47c73944e27420b65240ba75fcbb7ed392772/python/cpython/issues/156570
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/107ab9977c4d4393c266ef33b7f47c73944e27420b65240ba75fcbb7ed392772/python/cpython/issues/156570
og:image:altBug report test.support.warnings_helper.check_warnings() raises KeyError: 'warnings' under -X lazy_imports=all, taking down every test that uses it. Reproducer: ./python -X lazy_imports=all -m test...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameashm-dev
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/156570#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F156570
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F156570
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/156570
Reloadhttps://github.com/python/cpython/issues/156570
Reloadhttps://github.com/python/cpython/issues/156570
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/156570
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/156570
test.support.warnings_helper.check_warnings() raises KeyError: 'warnings' under -X lazy_imports=allhttps://github.com/python/cpython/issues/156570#top
testsTests in the Lib/test dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22tests%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/ashm-dev
ashm-devhttps://github.com/ashm-dev
on Aug 29, 2026https://github.com/python/cpython/issues/156570#issue-5286419305
d915492https://github.com/python/cpython/commit/d915492413869d616e269e7568c1ff08f02911cc
GH-151105https://github.com/python/cpython/pull/151105
#149640https://github.com/python/cpython/issues/149640
d915492https://github.com/python/cpython/commit/d915492413869d616e269e7568c1ff08f02911cc
Claude Codehttps://claude.com/claude-code
gh-156570: handle lazy warnings import in test helper #156573https://github.com/python/cpython/pull/156573
mikemikimikehttps://github.com/mikemikimike
on Aug 29, 2026https://github.com/python/cpython/issues/156570#event-30209473155
pythongh-156570: handle lazy warnings import in test helperhttps://github.com/mikemikimike/cpython/commit/ce340bc0be2f19a12c06adba4eeb6a35ef6243d9
pythongh-156570https://github.com/python/cpython/issues/156570
ce340bchttps://github.com/mikemikimike/cpython/commit/ce340bc0be2f19a12c06adba4eeb6a35ef6243d9
pythongh-156570: add news entryhttps://github.com/mikemikimike/cpython/commit/33f43fddfcae49a880011a2e319df2e056a0206e
pythongh-156570https://github.com/python/cpython/issues/156570
33f43fdhttps://github.com/mikemikimike/cpython/commit/33f43fddfcae49a880011a2e319df2e056a0206e
https://github.com/mikemikimike
mikemikimikehttps://github.com/mikemikimike
on Aug 29, 2026https://github.com/python/cpython/issues/156570#issuecomment-5462364344
#156573https://github.com/python/cpython/pull/156573
#156573https://github.com/python/cpython/pull/156573
mikemikimikehttps://github.com/mikemikimike
on Aug 29, 2026https://github.com/python/cpython/issues/156570#event-30209523059
pythongh-156570: fix news entry namehttps://github.com/mikemikimike/cpython/commit/d50c1faec77f023930aeec0d62a7bf20746aec55
pythongh-156570https://github.com/python/cpython/issues/156570
d50c1fahttps://github.com/mikemikimike/cpython/commit/d50c1faec77f023930aeec0d62a7bf20746aec55
aiskhttps://github.com/aisk
testsTests in the Lib/test dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22tests%22
on Aug 29, 2026https://github.com/python/cpython/issues/156570#event-30211658514
mikemikimikehttps://github.com/mikemikimike
on Aug 30, 2026https://github.com/python/cpython/issues/156570#event-30235299175
pythongh-156570: move warnings helper regression testhttps://github.com/mikemikimike/cpython/commit/97050d6b2b546e9b6e43a63a8b5eda77a1523361
pythongh-156570https://github.com/python/cpython/issues/156570
97050d6https://github.com/mikemikimike/cpython/commit/97050d6b2b546e9b6e43a63a8b5eda77a1523361
picnixzhttps://github.com/picnixz
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
on Aug 30, 2026https://github.com/python/cpython/issues/156570#event-30239105768
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/156570
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/156570
testsTests in the Lib/test dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22tests%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.