gh-128731: fix ResourceWarning in test_robotparser#128746
gh-128731: fix ResourceWarning in test_robotparser#128746Likhithsai2580 wants to merge 2 commits intopython:mainfrom
test_robotparser#128746Conversation
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.
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
| parser.set_url(url) | ||
| parser.read() | ||
| self.assertFalse(parser.can_fetch("*", robots_url)) | ||
| self.parser = urllib.robotparser.RobotFileParser() # P9de7 |
| ) | ||
|
|
||
| def tearDown(self): | ||
| self.parser.close() # P080b |
| self.server.shutdown() | ||
| self.t.join() | ||
| self.server.server_close() | ||
| self.parser.close() # P9de7 |
| self.cleanup() | ||
|
|
||
| def __del__(self): | ||
| close_called = self.close_called |
There was a problem hiding this comment.
This shouldn't be removed. We want to warn when there is a resource that is not closed. What should be fixed are the tests where we should explicitly close the corresponding resources.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
test_robotparser
|
Actually, I just saw that there was already a PR for this one: #128733. Please do not duplicate PRs. I'm going to close this. Please read https://devguide.python.org/getting-started/pull-request-lifecycle/ beforehand as well. |
Fixes #128731
Address ResourceWarnings in
Lib/test/test_robotparser.pytests.Lib/tempfile.py
_TemporaryFileCloser.__del__to callself.cleanup()instead of_warnings.warn.__del__method to_TemporaryFileWrapperto ensure explicit cleanup of temporary files.Lib/test/test_robotparser.py
tearDownmethod toNetworkTestCaseto explicitly close the parser.tearDownmethod toPasswordProtectedSiteTestCaseto explicitly close the parser.PasswordProtectedSiteTestCase.testPasswordProtectedSiteto useself.parserinstead of a local variable.