From e4ad48bb791335ed4ecd4cfe6d5f20ab6a1a2551 Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Fri, 1 Dec 2023 14:15:04 +0100 Subject: [PATCH] Add option to not remove temporary directories Convenient for debugging purposes in order to keep directories without rewriting a test using a tempdir. --- python/sdist/amici/testing.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/python/sdist/amici/testing.py b/python/sdist/amici/testing.py index cdee80b1f0..8d4a73fbe1 100644 --- a/python/sdist/amici/testing.py +++ b/python/sdist/amici/testing.py @@ -32,7 +32,19 @@ class TemporaryDirectoryWinSafe(TemporaryDirectory): such failures. """ + def __init__(self, *args, delete=True, **kwargs): + super().__init__(*args, **kwargs) + # TODO Python3.12 TemporaryDirectory already has a delete argument + # remove this once we drop support for Python3.11 + self.delete = delete + + if not self.delete: + self._finalizer.detach() + def cleanup(self): + if not self.delete: + return + try: super().cleanup() except PermissionError as e: