From 13e010d4d0170c0ce1d359078a94cc6d65020a4b Mon Sep 17 00:00:00 2001 From: ptweezy Date: Sat, 24 Oct 2026 12:30:59 -0400 Subject: [PATCH 1/2] Remove the temporary files that the tests leave behind test_threaded_write and test_threaded_write_oversized_block_no_error never removed their NamedTemporaryFile(delete=False) files. BaseTest in test_gzip_compliance.py created a file in __init__(), but pytest creates TestCase instances while it collects tests, and only the instances that ran a test removed their file. test_repr and test_seek removed their files only when they passed. Use tmp_path, and create the file name in setUp(). --- tests/test_gzip_compliance.py | 9 +++------ tests/test_igzip.py | 12 ++++-------- tests/test_igzip_threaded.py | 8 ++++---- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/tests/test_gzip_compliance.py b/tests/test_gzip_compliance.py index 5d71577c..bca9fd40 100644 --- a/tests/test_gzip_compliance.py +++ b/tests/test_gzip_compliance.py @@ -65,14 +65,11 @@ def seek(self, *args): class BaseTest(unittest.TestCase): - def __init__(self, methodName): + def setUp(self): + # Make a unique file name. The tests create the file themselves. fileno, self.filename = tempfile.mkstemp() os.close(fileno) - super().__init__(methodName) - - def setUp(self): - if os.path.exists(self.filename): - os.unlink(self.filename) + os.unlink(self.filename) def tearDown(self): if os.path.exists(self.filename): diff --git a/tests/test_igzip.py b/tests/test_igzip.py index 4f0e44f3..f185ac80 100644 --- a/tests/test_igzip.py +++ b/tests/test_igzip.py @@ -14,7 +14,6 @@ import itertools import os import re -import shutil import struct import subprocess import sys @@ -39,11 +38,9 @@ def test_wrong_compresslevel_igzipfile(): error.match("Compression level should be between 0 and 3") -def test_repr(): - tempdir = tempfile.mkdtemp() - with igzip.IGzipFile(os.path.join(tempdir, "test.gz"), "wb") as test: +def test_repr(tmp_path): + with igzip.IGzipFile(str(tmp_path / "test.gz"), "wb") as test: assert "