]> git.lttng.org Git - lttng-tools.git/commitdiff
Tests: Add pre-delete callbacks to TemporaryDirectory destructor
authorKienan Stewart <kstewart@efficios.com>
Wed, 13 Nov 2024 15:53:18 +0000 (10:53 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 3 Dec 2024 18:34:51 +0000 (13:34 -0500)
This will allow certain test clean-up operations (e.g., `umount`) to
be run before trying to to remove the directory.

Change-Id: I193030dfe4aeb0eeebc4370849681cbd9dcf500e
Signed-off-by: Kienan Stewart <kstewart@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
tests/utils/lttngtest/environment.py

index 03c1b5c8168b2e8d97e2b0886da82bbf52fc8ab4..1cc87a1fe4fdfa0be522f20f0578ebb740f83dfb 100644 (file)
@@ -32,11 +32,19 @@ import bt2
 class TemporaryDirectory:
     def __init__(self, prefix):
         # type: (str) -> None
+        self._cleanup_callbacks = []
         self._directory_path = tempfile.mkdtemp(prefix=prefix)
 
     def __del__(self):
-        if os.getenv("LTTNG_TEST_PRESERVE_TEST_ENV", "0") != "1":
-            shutil.rmtree(self._directory_path, ignore_errors=True)
+        try:
+            for func, args, kwargs in self._cleanup_callbacks:
+                func(*args, **kwargs)
+        finally:
+            if os.getenv("LTTNG_TEST_PRESERVE_TEST_ENV", "0") != "1":
+                shutil.rmtree(self._directory_path, ignore_errors=True)
+
+    def add_cleanup_callback(self, func, *args, **kwargs):
+        self._cleanup_callbacks.append((func, args, kwargs))
 
     @property
     def path(self):
This page took 0.031094 seconds and 4 git commands to generate.