[elbe-devel] [PATCH 09/11] elbepack: test_xml: clean up initvm on failures
Thomas Weißschuh
thomas.weissschuh at linutronix.de
Thu Aug 8 11:38:20 CEST 2024
If the test setup or execution fails, make sure to clean up the initvm.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
elbepack/tests/test_xml.py | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/elbepack/tests/test_xml.py b/elbepack/tests/test_xml.py
index b247cc10ff09..dcf1dfba321f 100644
--- a/elbepack/tests/test_xml.py
+++ b/elbepack/tests/test_xml.py
@@ -24,6 +24,12 @@ def initvm(tmp_path_factory, request):
def initvm_func(subcmd, *args):
run_elbe_subcommand(['initvm', subcmd, '--directory', initvm_dir, *args])
+ def destroy_initvm():
+ with contextlib.suppress(Exception):
+ initvm_func('stop')
+ with contextlib.suppress(Exception):
+ initvm_func('destroy')
+
if request.config.getoption('--elbe-use-existing-initvm'):
yield initvm_func
return
@@ -35,14 +41,13 @@ def initvm(tmp_path_factory, request):
# each test. This is very slow and unlikely to work, so remember the failure.
def error_func(*args, _initvm_exception, **kwargs):
raise RuntimeError('initvm setup failed') from _initvm_exception
+ destroy_initvm()
yield functools.partial(error_func, _initvm_exception=e)
else:
- yield initvm_func
-
- with contextlib.suppress(Exception):
- initvm_func('stop')
- with contextlib.suppress(Exception):
- initvm_func('destroy')
+ try:
+ yield initvm_func
+ finally:
+ destroy_initvm()
def _delete_project(uuid):
--
2.46.0
More information about the elbe-devel
mailing list