From bc44d60d188ed79a86ec24c289f3b86c54258d24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Fri, 7 Aug 2026 05:16:16 +0800 Subject: [PATCH] Close the HTTP error fixtures when the test ends Co-Authored-By: Claude Opus 5 (1M context) --- tools/tests/test_fetch_artists.py | 9 +++++---- tools/tests/test_fetch_lyrics.py | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/tools/tests/test_fetch_artists.py b/tools/tests/test_fetch_artists.py index 827836f..1cdab9b 100644 --- a/tools/tests/test_fetch_artists.py +++ b/tools/tests/test_fetch_artists.py @@ -106,15 +106,16 @@ class TestFetchArtists(unittest.TestCase): = json.dumps(payload).encode("utf-8") return response - @staticmethod - def __http_error(status: int) -> urllib.error.HTTPError: - """Build an HTTP error. + def __http_error(self, status: int) -> urllib.error.HTTPError: + """Build an HTTP error, closed when the test ends. :param status: The HTTP status code. :return: The HTTP error. """ - return urllib.error.HTTPError( + error: urllib.error.HTTPError = urllib.error.HTTPError( "https://example.com/", status, "Error", None, None) + self.addCleanup(error.close) + return error @staticmethod def __claim(qid: str) -> dict[str, Any]: diff --git a/tools/tests/test_fetch_lyrics.py b/tools/tests/test_fetch_lyrics.py index c645350..a73840d 100644 --- a/tools/tests/test_fetch_lyrics.py +++ b/tools/tests/test_fetch_lyrics.py @@ -112,14 +112,15 @@ class TestFetchLyrics(unittest.TestCase): = json.dumps(payload).encode("utf-8") return response - @staticmethod - def __not_found() -> urllib.error.HTTPError: - """Build an HTTP 404 error. + def __not_found(self) -> urllib.error.HTTPError: + """Build an HTTP 404 error, closed when the test ends. :return: The HTTP 404 error. """ - return urllib.error.HTTPError( + error: urllib.error.HTTPError = urllib.error.HTTPError( "https://example.com/", 404, "Not Found", None, None) + self.addCleanup(error.close) + return error def __run_fetch(self) -> tuple[int, str]: """Run the fetcher with the standard error captured.