]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
tests/functional: purge scratch dir on test startup
authorDaniel P. Berrangé <berrange@redhat.com>
Mon, 8 Sep 2025 13:57:22 +0000 (14:57 +0100)
committerThomas Huth <thuth@redhat.com>
Tue, 9 Sep 2025 13:45:33 +0000 (15:45 +0200)
The test suite purges the scratch dir in the tearDown method, but
if python crashes (or is non-gracefully killed) this won't get run.
Also the user can set QEMU_TEST_KEEP_SCRATCH to disable cleanup.

Purging the scratch dir on startup ensures that tests always run
from a clean state.

Reported-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Message-ID: <20250908135722.3375580-5-berrange@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
tests/functional/qemu_test/testcase.py

index faa0a4f0db23e0c4daed50a9a20beb489b4d34c1..2c0abde395785b4a92b78b95d52bccf9586466ab 100644 (file)
@@ -205,6 +205,10 @@ class QemuBaseTest(unittest.TestCase):
         self.outputdir = self.build_file('tests', 'functional',
                                          self.arch, self.id())
         self.workdir = os.path.join(self.outputdir, 'scratch')
+        if os.path.exists(self.workdir):
+            # Purge as safety net in case of unclean termination of
+            # previous test, or use of QEMU_TEST_KEEP_SCRATCH
+            shutil.rmtree(self.workdir)
         os.makedirs(self.workdir, exist_ok=True)
 
         self.log_filename = self.log_file('base.log')