File: conftest.py

package info (click to toggle)
debugpy 1.8.12%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,424 kB
  • sloc: python: 14,451; sh: 184; makefile: 33
file content (50 lines) | stat: -rw-r--r-- 1,482 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
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE in the project root
# for license information.

"""pytest configuration.
"""

import os
import re

import pytest


pytest_plugins = ["tests.pytest_fixtures", "tests.pytest_hooks"]


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_re1 = re.compile(r' (SKIPPED|PASSED|XFAIL) (test\S*)')
        test_re2 = re.compile(r'(test\S*) [^ ]*(SKIPPED|PASSED|XFAIL)')
        with open('pytest_log.txt') as logfile:
            for line in logfile:
                if match := test_re1.search(line):
                    tests.add(match.group(2))
                elif match := test_re2.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)