Skip already passed tests on subsequent pytest runs
authorJulian Gilbey <jdg@debian.org>
Mon, 5 Sep 2022 20:56:24 +0000 (21:56 +0100)
committerJulian Gilbey <jdg@debian.org>
Mon, 5 Sep 2022 20:56:24 +0000 (21:56 +0100)
Forwarded: not-needed
Origin: https://github.com/spyder-ide/spyder/blob/5.x/conftest.py
Last-Update: 2022-09-05

 This is based on the mechanism in Spyder.

Gbp-Pq: Name improve-multiple-test-runs.patch

conftest.py

index c46c3f9f5511d1da1be538f9fc4cd9f2ddd2a0e2..d2dea8df0de50c7ca8d8f1d968afb6cbc532dc0f 100644 (file)
@@ -5,9 +5,44 @@ from tests_python.debug_constants import TEST_CYTHON
 from tests_python.debug_constants import PYDEVD_TEST_VM
 import site
 import os
+import re
 from _pydev_bundle import pydev_log
 
 
+def get_passed_tests():
+    """
+    Get the list of passed tests by inspecting the log generated by pytest.
+
+    This is useful on CIs to restart the test suite from the point where a
+    segfault was thrown by it.
+    """
+    # This assumes the pytest log is placed next to this file. That's where
+    # we put it on CIs.
+    tests = set()
+    if os.path.isfile('pytest_log.txt'):
+        # Detect all tests that passed before.
+        test_re = re.compile(r'(test.*) [^ ]*(SKIPPED|PASSED|XFAIL)')
+        with open('pytest_log.txt') as logfile:
+            for line in logfile:
+                if match := test_re.match(line):
+                    tests.add(match.group(1))
+
+    return tests
+
+
+def pytest_collection_modifyitems(config, items):
+    """
+    Decide what tests to run (slow or fast) according to the --run-slow
+    option.
+    """
+    passed_tests = get_passed_tests()
+    skip_passed = pytest.mark.skip(reason="Test passed in previous runs")
+
+    for item in items:
+        if item.nodeid in passed_tests:
+            item.add_marker(skip_passed)
+
+
 def pytest_report_header(config):
     print('PYDEVD_USE_CYTHON: %s' % (TEST_CYTHON,))
     print('PYDEVD_TEST_VM: %s' % (PYDEVD_TEST_VM,))