From f6a0205bab3ee6222183f0ccedc90311b5894b28 Mon Sep 17 00:00:00 2001 From: Julian Gilbey Date: Mon, 5 Sep 2022 21:56:24 +0100 Subject: [PATCH] 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. Gbp-Pq: Name improve-multiple-test-runs.patch --- conftest.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/conftest.py b/conftest.py index c46c3f9..d2dea8d 100644 --- a/conftest.py +++ b/conftest.py @@ -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,)) -- 2.30.2