Add CLI arg to keep scratch files after test execution, equivalent to
setting QEMU_TEST_KEEP_SCRATCH env var.
Suggested-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
---
tests/functional/qemu_test/testcase.py | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/tests/functional/qemu_test/testcase.py b/tests/functional/qemu_test/testcase.py
index 3ecaaeffd4df2945fb4c44b4ddef6911527099b9..9b00c63e6ca7a2a669fd456f1d1b51501ce4a726 100644
--- a/tests/functional/qemu_test/testcase.py
+++ b/tests/functional/qemu_test/testcase.py
@@ -43,6 +43,13 @@ def parse_args(test_name: str) -> argparse.Namespace:
help="Also print test and console logs on stdout. This will make the"
" TAP output invalid and is meant for debugging only.",
)
+ parser.add_argument(
+ "--keep-scratch",
+ action="store_true",
+ help="Do not purge any scratch files created during the tests. "
+ "This is equivalent to setting QEMU_TEST_KEEP_SCRATCH=1 in the "
+ "environment.",
+ )
return parser.parse_args()
@@ -214,6 +221,9 @@ def setUp(self):
path = os.path.basename(sys.argv[0])[:-3]
args = parse_args(path)
self.stdout_handler = None
+ self.keep_scratch = (
+ "QEMU_TEST_KEEP_SCRATCH" in os.environ or args.keep_scratch
+ )
if args.debug:
self.stdout_handler = logging.StreamHandler(sys.stdout)
self.stdout_handler.setLevel(logging.DEBUG)
@@ -255,8 +265,10 @@ def setUp(self):
self.skipTest('One or more assets is not available')
def tearDown(self):
- if "QEMU_TEST_KEEP_SCRATCH" not in os.environ:
+ if not self.keep_scratch:
shutil.rmtree(self.workdir)
+ else:
+ self.log.info(f"Kept scratch files in {self.workdir}")
if self.socketdir is not None:
shutil.rmtree(self.socketdir.name)
self.socketdir = None
--
2.47.2
On 18/07/2025 13.04, Manos Pitsidianakis wrote:
> Add CLI arg to keep scratch files after test execution, equivalent to
> setting QEMU_TEST_KEEP_SCRATCH env var.
>
> Suggested-by: Alex Bennée <alex.bennee@linaro.org>
> Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
> ---
> tests/functional/qemu_test/testcase.py | 14 +++++++++++++-
> 1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/tests/functional/qemu_test/testcase.py b/tests/functional/qemu_test/testcase.py
> index 3ecaaeffd4df2945fb4c44b4ddef6911527099b9..9b00c63e6ca7a2a669fd456f1d1b51501ce4a726 100644
> --- a/tests/functional/qemu_test/testcase.py
> +++ b/tests/functional/qemu_test/testcase.py
> @@ -43,6 +43,13 @@ def parse_args(test_name: str) -> argparse.Namespace:
> help="Also print test and console logs on stdout. This will make the"
> " TAP output invalid and is meant for debugging only.",
> )
> + parser.add_argument(
> + "--keep-scratch",
> + action="store_true",
> + help="Do not purge any scratch files created during the tests. "
> + "This is equivalent to setting QEMU_TEST_KEEP_SCRATCH=1 in the "
> + "environment.",
> + )
> return parser.parse_args()
>
>
> @@ -214,6 +221,9 @@ def setUp(self):
> path = os.path.basename(sys.argv[0])[:-3]
> args = parse_args(path)
> self.stdout_handler = None
> + self.keep_scratch = (
> + "QEMU_TEST_KEEP_SCRATCH" in os.environ or args.keep_scratch
> + )
> if args.debug:
> self.stdout_handler = logging.StreamHandler(sys.stdout)
> self.stdout_handler.setLevel(logging.DEBUG)
> @@ -255,8 +265,10 @@ def setUp(self):
> self.skipTest('One or more assets is not available')
>
> def tearDown(self):
> - if "QEMU_TEST_KEEP_SCRATCH" not in os.environ:
> + if not self.keep_scratch:
> shutil.rmtree(self.workdir)
> + else:
> + self.log.info(f"Kept scratch files in {self.workdir}")
> if self.socketdir is not None:
> shutil.rmtree(self.socketdir.name)
> self.socketdir = None
>
Acked-by: Thomas Huth <thuth@redhat.com>
© 2016 - 2025 Red Hat, Inc.