From 16d340156d9bd544e4b567c46ebe9ca82aae88fd Mon Sep 17 00:00:00 2001 From: Keith Manville Date: Thu, 16 Jan 2025 15:47:04 -0500 Subject: [PATCH] fix: handle tmp file deletion manually --- tests/unit/restapi/v1/conftest.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/unit/restapi/v1/conftest.py b/tests/unit/restapi/v1/conftest.py index 9a86fa7fe..44290f0e6 100644 --- a/tests/unit/restapi/v1/conftest.py +++ b/tests/unit/restapi/v1/conftest.py @@ -737,16 +737,15 @@ def registered_mlflowrun_incomplete( def resources_tar_file() -> DioptraFile: os.chdir(Path(__file__).absolute().parent / "resource_import_files") - f = NamedTemporaryFile(suffix=".tar.gz") - with tarfile.open(fileobj=f, mode="w:gz") as tar: - tar.add("dioptra.toml") - tar.add("plugins", recursive=True) - tar.add(Path("examples", "hello-world.yaml")) - f.seek(0) + with NamedTemporaryFile(suffix=".tar.gz", delete=False) as f: + with tarfile.open(fileobj=f, mode="w:gz") as tar: + tar.add("dioptra.toml") + tar.add("plugins", recursive=True) + tar.add(Path("examples", "hello-world.yaml")) yield select_one_or_more_files([f.name])[0] - f.close() + os.unlink(f.name) @pytest.fixture