Title: `logging.captureWarnings` and `warnings.catch_warnings` do not play well together · Issue #139355 · python/cpython · GitHub
Open Graph Title: `logging.captureWarnings` and `warnings.catch_warnings` do not play well together · Issue #139355 · python/cpython
X Title: `logging.captureWarnings` and `warnings.catch_warnings` do not play well together · Issue #139355 · python/cpython
Description: Bug report Bug description: When logging.captureWarnings(True) is called within a warnings.catch_warnings(record=True) context warnings emitted during the context are not recorded. import logging, warnings with warnings.catch_warnings(re...
Open Graph Description: Bug report Bug description: When logging.captureWarnings(True) is called within a warnings.catch_warnings(record=True) context warnings emitted during the context are not recorded. import logging, ...
X Description: Bug report Bug description: When logging.captureWarnings(True) is called within a warnings.catch_warnings(record=True) context warnings emitted during the context are not recorded. import logging, ...
Opengraph URL: https://github.com/python/cpython/issues/139355
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`logging.captureWarnings` and `warnings.catch_warnings` do not play well together","articleBody":"# Bug report\n\n### Bug description:\n\nWhen `logging.captureWarnings(True)` is called within a `warnings.catch_warnings(record=True)` context warnings emitted during the context are not recorded.\n\n```python\nimport logging, warnings\nwith warnings.catch_warnings(record=True) as rec:\n logging.captureWarnings(True)\n warnings.warn(\"foo\")\nassert len(rec) == 1 # fails since len(rec) == 0\n```\n\none work-around for this is to enable `captureWarnings` outside the context\n\n```python\nimport logging, warnings\nlogging.captureWarnings(True)\nwith warnings.catch_warnings(record=True) as rec:\n warnings.warn(\"foo\")\nassert len(rec) == 1\n```\n\nI tested the above examples on 3.10, 3.13 and 3.14.0b2.\n\nHowever on 3.14.0b2 with `PYTHON_CONTEXT_AWARE_WARNINGS=1` (to pull in the changes from https://github.com/python/cpython/pull/130010) the second example (enabling `captureWarnings` outside the `catch_warnings`) no longer works.\n\n### CPython versions tested on:\n\n3.13\n\n### Operating systems tested on:\n\nmacOS","author":{"url":"https://github.com/braingram","@type":"Person","name":"braingram"},"datePublished":"2025-09-26T14:00:36.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/139355/cpython/issues/139355"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:48797ec4-3cfd-cae4-0b52-dff11e21d001 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 849A:95C7C:88A268:B70201:6A54207B |
| html-safe-nonce | fd0b8937e93fa32795bcd64a663db005df619ae33741eb2283c6e9c285486244 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NDlBOjk1QzdDOjg4QTI2ODpCNzAyMDE6NkE1NDIwN0IiLCJ2aXNpdG9yX2lkIjoiMTM3MjgzNjY3Mzg5ODE2MDI1MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 33fb43d1b21124297fa3a4ccbf5e577eb4f48ad2dcae399cb3402c0930fd9667 |
| hovercard-subject-tag | issue:3457815882 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/139355/issue_layout |
| twitter:image | https://opengraph.githubassets.com/39a854fdd9fe10469cf132b354421667ee74826ba59728b1d2bc64fb4d50bea7/python/cpython/issues/139355 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/39a854fdd9fe10469cf132b354421667ee74826ba59728b1d2bc64fb4d50bea7/python/cpython/issues/139355 |
| og:image:alt | Bug report Bug description: When logging.captureWarnings(True) is called within a warnings.catch_warnings(record=True) context warnings emitted during the context are not recorded. import logging, ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | braingram |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width