Title: gh-89900: Add option to preserve existing handlers for assertLogs by Yuheng3107 · Pull Request #143970 · python/cpython · GitHub
Open Graph Title: gh-89900: Add option to preserve existing handlers for assertLogs by Yuheng3107 · Pull Request #143970 · python/cpython
X Title: gh-89900: Add option to preserve existing handlers for assertLogs by Yuheng3107 · Pull Request #143970 · python/cpython
Description: Closes #89900 Description The Problem At the moment, assertLogs removes the handlers attached to the logger. In general this is good, because it reduces message spamming in the test logs. However, if the code being tested is relying on a handler to do something, then the test fails because the handler is being removed. This leads to the situation that the same exact test must be run twice: first time within the context manager, to assert that specific messages were logged (using with self.assertLogs()) second time, without the assertLogs to ensure the code that uses a handler does the right thing The Fix Added optional keep_handlers param in assertLogs inside Lib/unittest/case.py to optionally preserve existing handlers for assertLogs, preventing the situation described above where the same exact test must be run twice Since keep_handlers is False by default, this change is backwards-compatible. Tests Added new test cases in Lib/test/test_unittest to ensure keep_handlers=True preserves existing handlers. Validation Ran ./python.exe -m test test_unittest and passed all 1093 tests Issue: gh-89900 📚 Documentation preview 📚: https://cpython-previews--143970.org.readthedocs.build/
Open Graph Description: Closes #89900 Description The Problem At the moment, assertLogs removes the handlers attached to the logger. In general this is good, because it reduces message spamming in the test logs. However,...
X Description: Closes #89900 Description The Problem At the moment, assertLogs removes the handlers attached to the logger. In general this is good, because it reduces message spamming in the test logs. However,...
Opengraph URL: https://github.com/python/cpython/pull/143970
X: @github
Domain: patch-diff.githubusercontent.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:76aa3cb4-0d80-d381-e9e3-be122cacb271 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | AC08:2B5ABB:E578F:139344:696F2941 |
| html-safe-nonce | 87d83e825e33a22207f288febdd5339e1fafab8cd194612e0963b403d91b9c37 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQzA4OjJCNUFCQjpFNTc4RjoxMzkzNDQ6Njk2RjI5NDEiLCJ2aXNpdG9yX2lkIjoiMjcwNjAwODA1MTcwODUzNzE1MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8fd678cb6be85f621e35967bc76453d21434633e998c760b4a8000b0965d6113 |
| hovercard-subject-tag | pull_request:3184315718 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/python/cpython/pull/143970/files |
| twitter:image | https://avatars.githubusercontent.com/u/7950607?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/7950607?s=400&v=4 |
| og:image:alt | Closes #89900 Description The Problem At the moment, assertLogs removes the handlers attached to the logger. In general this is good, because it reduces message spamming in the test logs. However,... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b278ad162d35332b6de714dfb005de04386c4d92df6475522bef910f491a35ee |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 39aed5006635ab6f45e6b77d23e73b08a00272a3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width