Browse Source

TESTS: add pytest `incremental` marker to mark tests as expected to fail if previous test failed

see http://stackoverflow.com/a/12579625/107049
Thomas LEVEIL 8 years ago
parent
commit
e25c78b00a
1 changed files with 12 additions and 0 deletions
  1. 12 0
      test/conftest.py

+ 12 - 0
test/conftest.py

@@ -445,6 +445,18 @@ def pytest_runtest_logreport(report):
                 report.longrepr.addsection('nginx-proxy conf', get_nginx_conf_from_container(container))
                 report.longrepr.addsection('nginx-proxy conf', get_nginx_conf_from_container(container))
 
 
 
 
+# Py.test `incremental` marker, see http://stackoverflow.com/a/12579625/107049
+def pytest_runtest_makereport(item, call):
+    if "incremental" in item.keywords:
+        if call.excinfo is not None:
+            parent = item.parent
+            parent._previousfailed = item
+
+
+def pytest_runtest_setup(item):
+    previousfailed = getattr(item.parent, "_previousfailed", None)
+    if previousfailed is not None:
+        pytest.xfail("previous test failed (%s)" % previousfailed.name)
 
 
 ###############################################################################
 ###############################################################################
 # 
 #