Describe the problem
make_nifti_image in tests/test_utils.py creates a NIfTI file inside a fresh tempfile.mkdtemp() directory when no dir= is given, but returns only the file path. Its docstring assigns cleanup to the caller:
Create a temporary nifti image on the disk and return the image name.
User is responsible for deleting the temporary file when done with it.
11 of the 15 call sites across 9 test files discard the returned path entirely. The other four, in tests/data/test_nifti_rw.py and tests/integration/test_integration_sliding_window.py, do try to honour the contract, but they os.remove the file and never remove the directory holding it. Running tests/data/test_nifti_rw.py alone leaves 65 empty directories behind.
So every call site leaks a directory. The helper creates two things and hands back one, and both callers who tried to clean up got it wrong the same way.
tests/data/test_make_nifti.py:30 additionally calls tempfile.mkdtemp() inside a loop at module scope, leaking three more directories at import time, before any test runs.
To reproduce
before=$(ls /tmp | wc -l)
python -m pytest tests/data/test_nifti_rw.py tests/data/test_make_nifti.py \
tests/transforms/inverse/test_invert.py \
tests/transforms/utility/test_splitdimd.py -q
after=$(ls /tmp | wc -l); echo $((after - before))
77 entries left behind: a mix of empty directories (callers that removed the file but not the directory) and populated ones (callers that removed nothing).
Expected behavior
A test run leaves no new entries under the system temp directory.
Context
Surfaced by #9040 (comment), where fixing it was out of scope.
Describe the problem
make_nifti_imageintests/test_utils.pycreates a NIfTI file inside a freshtempfile.mkdtemp()directory when nodir=is given, but returns only the file path. Its docstring assigns cleanup to the caller:11 of the 15 call sites across 9 test files discard the returned path entirely. The other four, in
tests/data/test_nifti_rw.pyandtests/integration/test_integration_sliding_window.py, do try to honour the contract, but theyos.removethe file and never remove the directory holding it. Runningtests/data/test_nifti_rw.pyalone leaves 65 empty directories behind.So every call site leaks a directory. The helper creates two things and hands back one, and both callers who tried to clean up got it wrong the same way.
tests/data/test_make_nifti.py:30additionally callstempfile.mkdtemp()inside a loop at module scope, leaking three more directories at import time, before any test runs.To reproduce
77 entries left behind: a mix of empty directories (callers that removed the file but not the directory) and populated ones (callers that removed nothing).
Expected behavior
A test run leaves no new entries under the system temp directory.
Context
Surfaced by #9040 (comment), where fixing it was out of scope.