Skip to content

Use tmp_path for the temporary files that the tests leave behind - #294

Open
ptweezy wants to merge 2 commits into
pycompression:developfrom
ptweezy:test-temp-files
Open

ptweezy wants to merge 2 commits into
pycompression:developfrom
ptweezy:test-temp-files

Conversation

@ptweezy

@ptweezy ptweezy commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

A full test run leaves 11 files in the temporary directory:

  • 8 gzip files, about 10 MB in total, from NamedTemporaryFile(delete=False) in test_threaded_write and test_threaded_write_oversized_block_no_error.
  • 3 empty files from BaseTest.__init__() in tests/test_gzip_compliance.py. Since pytest 8.2, pytest creates the TestCase instances while it collects tests, plus one instance for each class that never runs a test. Only the instances that run a test remove their file.

The two threaded tests now use tmp_path, and BaseTest creates its file name in setUp(). test_repr and test_seek in tests/test_igzip.py removed their files only when they passed, so they use tmp_path too. With this PR, the tests leave files only in the tmp_path directories, and pytest keeps those for the last three runs only.

The second commit passes a list instead of an itertools.product iterator to parametrize for test_threaded_write, as #297 does for the other tests. It is here because this PR changes the next line.

This PR changes only tests, so it has no CHANGELOG entry.

Checklist

  • Pull request details were added to CHANGELOG.rst
  • Documentation was updated (if needed)

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().
@ptweezy ptweezy changed the title Remove the temporary files that the tests leave behind Use tmp_path for the temporary files that the tests leave behind Oct 24, 2026
pytest 10 turns the PytestRemovedIn10Warning for iterators into an
error. pycompression#297 changes the other calls, but this decorator is next to the
line that the previous commit changes.

This branch has not been deployed

No deployments
Sign up for free to 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