]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add custom flaky decorator to handle unstable tests
authorTom Krizek <tkrizek@isc.org>
Thu, 17 Aug 2023 08:30:46 +0000 (10:30 +0200)
committerMichal Nowak <mnowak@isc.org>
Tue, 22 Aug 2023 06:55:36 +0000 (08:55 +0200)
If the flaky plugin for pytest is available, use its decorator to
support re-running unstable tests. In case the package is missing,
execute the test as usual without attempts to re-run it in case of
failure.

This is mostly intended to increase the test stability in CI. Using a
custom decorator enables us to keep the flaky package as an optional
dependency.

(cherry picked from commit 5b703de733b1f53f0452e8e654459d7adeb9aa00)

bin/tests/system/pytest_custom_markers.py

index 7411afeafd2692186ede42f632a6ed4f39671605..ba3a9d4894a83f6396bd4b6c21a421644e5e35f6 100644 (file)
@@ -40,3 +40,21 @@ have_libxml2 = pytest.mark.skipif(
 have_json_c = pytest.mark.skipif(
     not feature_test("--have-json-c"), reason="json-c support disabled in the build"
 )
+
+
+try:
+    import flaky as flaky_pkg
+except ModuleNotFoundError:
+    # In case the flaky package is not installed, run the tests as usual
+    # without any attempts to re-run them.
+    # pylint: disable=unused-argument
+    def flaky(*args, **kwargs):
+        """Mock decorator that doesn't do anything special, just returns the function."""
+
+        def wrapper(wrapped_obj):
+            return wrapped_obj
+
+        return wrapper
+
+else:
+    flaky = flaky_pkg.flaky