File: improve-multiple-test-runs.patch

package info (click to toggle)
pydevd 3.4.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,892 kB
  • sloc: python: 77,580; cpp: 1,873; sh: 374; makefile: 50; ansic: 4
file content (61 lines) | stat: -rw-r--r-- 1,893 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
From: Julian Gilbey <jdg@debian.org>
Date: Tue, 28 Oct 2025 12:16:57 -0700
Subject: Skip already passed tests on subsequent pytest runs

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.
---
 conftest.py | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/conftest.py b/conftest.py
index 37728e6..893069b 100644
--- a/conftest.py
+++ b/conftest.py
@@ -5,9 +5,43 @@ 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):
+    """
+    Skip tests that passed on a previous run.
+    """
+    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,))