Description: Skip already passed tests on subsequent pytest runs
  This is based on the mechanism in Spyder, copied verbatim from the
  jupyter-client patch
Forwarded: not-needed
Origin: https://github.com/spyder-ide/spyder/blob/5.x/conftest.py
Author: Julian Gilbey <jdg@debian.org>
Last-Update: 2025-01-17

--- /dev/null
+++ b/qtconsole/tests/conftest.py
@@ -0,0 +1,37 @@
+import os
+import re
+
+import pytest
+
+
+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)
