From ce73b9106fca262232f043a142b45fe06f4f00fa Mon Sep 17 00:00:00 2001 From: Nick Tyler Date: Wed, 28 Aug 2024 10:52:15 -0700 Subject: [PATCH] Always cleanup temp files --- tests/conftest.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 1ba4ef1..edb918c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -192,12 +192,14 @@ def fake_key_file(tmp_path_factory): """ ) key_path.chmod(0o100600) - yield key_path - # make sure to cleanup the test since we put a file in ~/.sfapi_test - temp_path = Path().home() / ".sfapi_test1" - if temp_path.exists(): - (temp_path / "key.pem").unlink(missing_ok=True) - temp_path.rmdir() + try: + yield key_path + finally: + # make sure to cleanup the test since we put a file in ~/.sfapi_test + temp_path = Path().home() / ".sfapi_test1" + if temp_path.exists(): + (temp_path / "key.pem").unlink(missing_ok=True) + temp_path.rmdir() @pytest.fixture @@ -207,9 +209,11 @@ def empty_key_file(tmp_path_factory): # Makes an empty key key_path.write_text("") key_path.chmod(0o100600) - yield key_path - # make sure to cleanup the test since we put a file in ~/.sfapi_test - temp_path = Path().home() / ".sfapi_test2" - if temp_path.exists(): - (temp_path / "nokey.pem").unlink(missing_ok=True) - temp_path.rmdir() + try: + yield key_path + finally: + # make sure to cleanup the test since we put a file in ~/.sfapi_test + temp_path = Path().home() / ".sfapi_test2" + if temp_path.exists(): + (temp_path / "nokey.pem").unlink(missing_ok=True) + temp_path.rmdir()