[elbe-devel] [PATCH 08/11] elbepack: test_xml: remember initvm setup errors

Thomas Weißschuh thomas.weissschuh at linutronix.de
Thu Aug 8 11:38:19 CEST 2024


If the setup of a shared fixture fails then pytest will try to recreate
that fixture for the next test.
In the case of the initvm this is very slow and unlikely to help in the
first place.
Instead remember and propagate the first fixture failure to all users.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/tests/test_xml.py | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/elbepack/tests/test_xml.py b/elbepack/tests/test_xml.py
index f5d716763930..b247cc10ff09 100644
--- a/elbepack/tests/test_xml.py
+++ b/elbepack/tests/test_xml.py
@@ -3,6 +3,7 @@
 # SPDX-FileCopyrightText: 2020 Linutronix GmbH
 
 import contextlib
+import functools
 import io
 import pathlib
 import subprocess
@@ -27,9 +28,16 @@ def initvm(tmp_path_factory, request):
         yield initvm_func
         return
 
-    initvm_func('create', '--fail-on-warning')
-
-    yield initvm_func
+    try:
+        initvm_func('create', '--fail-on-warning')
+    except Exception as e:
+        # If the fixture setup fails, pytest will try to create the fixture for
+        # 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
+        yield functools.partial(error_func, _initvm_exception=e)
+    else:
+        yield initvm_func
 
     with contextlib.suppress(Exception):
         initvm_func('stop')

-- 
2.46.0



More information about the elbe-devel mailing list