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>
Acked-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
---
tests/functional/qemu_test/testcase.py | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/tests/functional/qemu_test/testcase.py b/tests/functional/qemu_test/testcase.py
index eedca7f1ad29c9e654cf56535acf9639d679f5c4..f7e306cf749e8b24a712b09dfe8673660cbb5085 100644
--- a/tests/functional/qemu_test/testcase.py
+++ b/tests/functional/qemu_test/testcase.py
@@ -35,6 +35,7 @@
class QemuBaseTest(unittest.TestCase):
debug: bool = False
+ keep_scratch: bool = "QEMU_TEST_KEEP_SCRATCH" in os.environ
"""
Class method that initializes class attributes from given command-line
@@ -53,8 +54,16 @@ def parse_args():
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.",
+ )
args = parser.parse_args()
QemuBaseTest.debug = args.debug
+ QemuBaseTest.keep_scratch |= args.keep_scratch
return
'''
@@ -262,8 +271,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 QemuBaseTest.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