Debian Codegraph @

tests/conftest.py

raw ◀ ▶
1 Debian patch touch this file
1 import asyncio
2 import os
•3 import re
4
5 if os.name == "nt":
6 asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) # type:ignore
7
8 import pytest
9
10 # Must be set before importing from `jupyter_core`.
11 os.environ["JUPYTER_PLATFORM_DIRS"] = "1"
12
13
14 pytest_plugins = ["pytest_jupyter", "pytest_jupyter.jupyter_client"]
15
16
17 @pytest.fixture(autouse=True)
18 def setup_environ(jp_environ):
19 pass
•20
21
22 def get_passed_tests():
23 """
24 Get the list of passed tests by inspecting the log generated by pytest.
25
26 This is useful on CIs to restart the test suite from the point where a
27 segfault was thrown by it.
28 """
29 # This assumes the pytest log is placed next to this file. That's where
30 # we put it on CIs.
31 tests = set()
32 if os.path.isfile('pytest_log.txt'):
33 # Detect all tests that passed before.
34 test_re = re.compile(r'(test.*) [^ ]*(SKIPPED|PASSED|XFAIL)')
35 with open('pytest_log.txt') as logfile:
36 for line in logfile:
37 if match := test_re.match(line):
38 tests.add(match.group(1))
39
40 return tests
41
42
43 def pytest_collection_modifyitems(config, items):
44 """
45 Skip tests that passed on a previous run.
46 """
47 passed_tests = get_passed_tests()
48 skip_passed = pytest.mark.skip(reason="Test passed in previous runs")
49
50 for item in items:
51 if item.nodeid in passed_tests:
52 item.add_marker(skip_passed)