gh-131807: fix ResourceWarning in test_ucn.py#131808
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a ResourceWarning in test_ucn.py by adjusting how network resource errors are handled during URL retrieval in tests.
- Introduces an explicit import for urllib.error.
- Splits exception handling into a specific block for urllib.error.HTTPError (with an explicit resource cleanup) and a combined block for OSError and HTTPException.
- Replaces the previous cleanup approach with a context manager for test data.
Comments suppressed due to low confidence (2)
Lib/test/test_ucn.py:185
- Ensure that calling e.close() on HTTPError is valid and necessary; if HTTPError does not implement a close() method or is already handled by a context manager, this call might be redundant or could lead to unexpected behavior.
except urllib.error.HTTPError as e:
Lib/test/test_ucn.py:187
- [nitpick] Consider using a more concise error message format without variable name expansion (e.g. using '{e}' instead of '{e=}') to prevent potentially exposing internal details.
self.skipTest(f"Could not retrieve {url} {e=}")
Co-authored-by: Victor Stinner <vstinner@python.org>
|
Thanks @graingert for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. |
(cherry picked from commit adb67ed) Co-authored-by: Thomas Grainger <tagrain@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org>
|
GH-131845 is a backport of this pull request to the 3.13 branch. |
(cherry picked from commit adb67ed) Co-authored-by: Thomas Grainger <tagrain@gmail.com> Co-authored-by: Victor Stinner <vstinner@python.org>
|
GH-131846 is a backport of this pull request to the 3.12 branch. |
|
Merged, thanks for the fix. |
|
|


Uh oh!
There was an error while loading. Please reload this page.