Skip to content

Avoid ResourceWarning: Implicitly cleaning up <addinfourl ...> - #591

Open
hroncok wants to merge 1 commit into
html5lib:masterfrom
hroncok:close
Open

Avoid ResourceWarning: Implicitly cleaning up <addinfourl ...>#591
hroncok wants to merge 1 commit into
html5lib:masterfrom
hroncok:close

Conversation

@hroncok

@hroncokhroncok commented Jan 14, 2026

Copy link
Copy Markdown
Contributor

Close the urllib.response.addinfourl by using a context manager.

Without this:

=================================== FAILURES ===================================
_________________________________ test session _________________________________
/usr/lib64/python3.14/tempfile.py:484: in __del__
_warnings.warn(self.warn_message, ResourceWarning)
E ResourceWarning: Implicitly cleaning up <addinfourl at 281473371898608 whose fp = <http.client.HTTPResponse object at 0xffff9fe82470>>
The above exception was the direct cause of the following exception:
/usr/lib/python3.14/site-packages/_pytest/runner.py:344: in from_call
result: TResult | None = func()
^^^^^^
/usr/lib/python3.14/site-packages/_pytest/runner.py:246: in <lambda>
lambda: runtest_hook(item=item, **kwds), when=when, reraise=reraise
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/usr/lib/python3.14/site-packages/pluggy/_hooks.py:512: in __call__
return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/usr/lib/python3.14/site-packages/pluggy/_manager.py:120: in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/usr/lib/python3.14/site-packages/_pytest/logging.py:850: in pytest_runtest_call
yield
/usr/lib/python3.14/site-packages/_pytest/capture.py:900: in pytest_runtest_call
return (yield)
^^^^^
/usr/lib/python3.14/site-packages/_pytest/skipping.py:263: in pytest_runtest_call
return (yield)
^^^^^
/usr/lib/python3.14/site-packages/_pytest/unraisableexception.py:158: in pytest_runtest_call
collect_unraisable(item.config)
/usr/lib/python3.14/site-packages/_pytest/unraisableexception.py:79: in collect_unraisable
raise errors[0]
/usr/lib/python3.14/site-packages/_pytest/unraisableexception.py:67: in collect_unraisable
warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))
E pytest.PytestUnraisableExceptionWarning: Exception ignored while calling deallocator <function _TemporaryFileCloser.__del__ at 0xffffa6b34720>: None

CPython reference: python/cpython@bad3cde

Close the urllib.response.addinfourl by using a context manager.
Without this:
=================================== FAILURES ===================================
_________________________________ test session _________________________________
/usr/lib64/python3.14/tempfile.py:484: in __del__
_warnings.warn(self.warn_message, ResourceWarning)
E ResourceWarning: Implicitly cleaning up <addinfourl at 281473371898608 whose fp = <http.client.HTTPResponse object at 0xffff9fe82470>>
The above exception was the direct cause of the following exception:
/usr/lib/python3.14/site-packages/_pytest/runner.py:344: in from_call
result: TResult | None = func()
^^^^^^
/usr/lib/python3.14/site-packages/_pytest/runner.py:246: in <lambda>
lambda: runtest_hook(item=item, **kwds), when=when, reraise=reraise
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/usr/lib/python3.14/site-packages/pluggy/_hooks.py:512: in __call__
return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/usr/lib/python3.14/site-packages/pluggy/_manager.py:120: in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/usr/lib/python3.14/site-packages/_pytest/logging.py:850: in pytest_runtest_call
yield
/usr/lib/python3.14/site-packages/_pytest/capture.py:900: in pytest_runtest_call
return (yield)
^^^^^
/usr/lib/python3.14/site-packages/_pytest/skipping.py:263: in pytest_runtest_call
return (yield)
^^^^^
/usr/lib/python3.14/site-packages/_pytest/unraisableexception.py:158: in pytest_runtest_call
collect_unraisable(item.config)
/usr/lib/python3.14/site-packages/_pytest/unraisableexception.py:79: in collect_unraisable
raise errors[0]
/usr/lib/python3.14/site-packages/_pytest/unraisableexception.py:67: in collect_unraisable
warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))
E pytest.PytestUnraisableExceptionWarning: Exception ignored while calling deallocator <function _TemporaryFileCloser.__del__ at 0xffffa6b34720>: None
CPython reference: python/cpython@bad3cde
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@hroncok