Temp directory context for cleaner code in tests
@@ -207,10 +207,12 @@ def test_dicom_listener_send_conflicting_file(listener, test_dataset):
@pytest.mark.pydicom
def test_dicom_listener_cli(test_dataset):
- test_directory = pathlib.Path(tempfile.mkdtemp())
-
scp_ae_title = "PYMEDPHYSTEST"
+ with tempfile.TemporaryDirectory() as tmp_directory:
+
+ test_directory = pathlib.Path(tmp_directory)
+
with process(
f"pymedphys dicom listen {TEST_PORT} -d {test_directory} -a {scp_ae_title}",
shell=True,
@@ -239,6 +241,3 @@ def test_dicom_listener_cli(test_dataset):
file_path = series_dir.joinpath(f"RP.{test_dataset.SOPInstanceUID}.dcm")
read_dataset = pydicom.read_file(file_path)
assert read_dataset.SeriesInstanceUID == test_dataset.SeriesInstanceUID
-
- # Clean up after ourselves
- shutil.rmtree(test_directory)
