Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResourceWarning in test_robotparser #128731

Closed
serhiy-storchaka opened this issue Jan 11, 2025 · 1 comment
Closed

ResourceWarning in test_robotparser #128731

serhiy-storchaka opened this issue Jan 11, 2025 · 1 comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Jan 11, 2025

Bug report

$ ./python -We -m test -vuall test_robotparser
...
test_read_404 (test.test_robotparser.NetworkTestCase.test_read_404) ... Warning -- Unraisable exception
Exception ignored in: <function _TemporaryFileCloser.__del__ at 0x7ff389434dd0>
Traceback (most recent call last):
  File "/home/serhiy/py/cpython/Lib/tempfile.py", line 483, in __del__
    _warnings.warn(self.warn_message, ResourceWarning)
ResourceWarning: Implicitly cleaning up <HTTPError 404: 'Not Found'>
ok
testPasswordProtectedSite (test.test_robotparser.PasswordProtectedSiteTestCase.testPasswordProtectedSite) ... Warning -- Unraisable exception
Exception ignored in: <function _TemporaryFileCloser.__del__ at 0x7ff389434dd0>
Traceback (most recent call last):
  File "/home/serhiy/py/cpython/Lib/tempfile.py", line 483, in __del__
    _warnings.warn(self.warn_message, ResourceWarning)
ResourceWarning: Implicitly cleaning up <HTTPError 403: 'Forbidden access'>
ok
...

Linked PRs

@serhiy-storchaka serhiy-storchaka added type-bug An unexpected behavior, bug, or error tests Tests in the Lib/test dir stdlib Python modules in the Lib dir and removed tests Tests in the Lib/test dir labels Jan 11, 2025
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Jan 11, 2025
Likhithsai2580 added a commit to Likhithsai2580/cpython that referenced this issue Jan 12, 2025
Fixes python#128731

Address ResourceWarnings in `Lib/test/test_robotparser.py` tests.

* **Lib/tempfile.py**
  - Modify `_TemporaryFileCloser.__del__` to call `self.cleanup()` instead of `_warnings.warn`.
  - Add a `__del__` method to `_TemporaryFileWrapper` to ensure explicit cleanup of temporary files.

* **Lib/test/test_robotparser.py**
  - Add a `tearDown` method to `NetworkTestCase` to explicitly close the parser.
  - Add a `tearDown` method to `PasswordProtectedSiteTestCase` to explicitly close the parser.
  - Update `PasswordProtectedSiteTestCase.testPasswordProtectedSite` to use `self.parser` instead of a local variable.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jan 12, 2025
…ead() (pythonGH-128733)

(cherry picked from commit 5e65a1a)

Co-authored-by: Serhiy Storchaka <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jan 12, 2025
…ead() (pythonGH-128733)

(cherry picked from commit 5e65a1a)

Co-authored-by: Serhiy Storchaka <[email protected]>
@serhiy-storchaka
Copy link
Member Author

The warning is only in the main branch, but it is better to backport this change to avoid dependency on the garbage collector.

See also #128734.

serhiy-storchaka added a commit that referenced this issue Jan 12, 2025
…otFileParser.read() (GH-128733) (GH-128756)

(cherry picked from commit 5e65a1a)

Co-authored-by: Serhiy Storchaka <[email protected]>
serhiy-storchaka added a commit that referenced this issue Jan 13, 2025
…otFileParser.read() (GH-128733) (GH-128755)

(cherry picked from commit 5e65a1a)

Co-authored-by: Serhiy Storchaka <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant