]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add --noclean option to pytest runner
authorTom Krizek <tkrizek@isc.org>
Thu, 12 Jan 2023 16:38:06 +0000 (17:38 +0100)
committerTom Krizek <tkrizek@isc.org>
Mon, 22 May 2023 12:11:38 +0000 (14:11 +0200)
Support the --noclean option to allow the user to keep the artifacts
from any test run.

bin/tests/system/conftest.py

index 306d29701ac66dcb169cd2844de84eef84ed4bf0..30a89395e1ceb403b0ab820e75a77c46194e51a7 100644 (file)
@@ -108,6 +108,14 @@ if os.getenv("LEGACY_TEST_RUNNER", "0") == "0":
 
     # --------------------------- pytest hooks -------------------------------
 
+    def pytest_addoption(parser):
+        parser.addoption(
+            "--noclean",
+            action="store_true",
+            default=False,
+            help="don't remove the temporary test directories with artifacts",
+        )
+
     def pytest_configure():
         # Ensure this hook only runs on the main pytest instance if xdist is
         # used to spawn other workers.
@@ -258,9 +266,12 @@ if os.getenv("LEGACY_TEST_RUNNER", "0") == "0":
             os.chdir(old_cwd)
             logger.debug("changed workdir to: %s", old_cwd)
 
-            # cases when tempdir should be kept are handled in follow-up commits
-            logger.debug("deleting temporary directory")
-            shutil.rmtree(testdir)
+            # Clean temporary dir unless it should be kept
+            if request.config.getoption("--noclean"):
+                logger.debug("--noclean requested, keeping temporary directory")
+            else:
+                logger.debug("deleting temporary directory")
+                shutil.rmtree(testdir)
 
     def _run_script(  # pylint: disable=too-many-arguments
         env,