File: improve-multiple-test-runs.patch

package info (click to toggle)
pydevd 2.9.5%2Bds-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 10,880 kB
  • sloc: python: 75,138; cpp: 1,851; sh: 310; makefile: 40; ansic: 4
file content (54 lines) | stat: -rw-r--r-- 1,686 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
Description: Skip already passed tests on subsequent pytest runs
  This is based on the mechanism in Spyder.
Forwarded: not-needed
Origin: https://github.com/spyder-ide/spyder/blob/5.x/conftest.py
Author: Julian Gilbey <jdg@debian.org>
Last-Update: 2022-09-05

--- a/conftest.py
+++ b/conftest.py
@@ -5,9 +5,44 @@
 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,))