forked from pwndbg/pwndbg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpytests_collect.py
42 lines (28 loc) · 1005 Bytes
/
pytests_collect.py
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
from __future__ import annotations
import os
import sys
import pytest
TESTS_PATH = os.environ.get("TESTS_PATH")
if TESTS_PATH is None:
print("'TESTS_PATH' environment variable not set. Failed to collect tests.")
sys.stdout.flush()
os._exit(1)
class CollectTestFunctionNames:
"""See https://github.com/pytest-dev/pytest/issues/2039#issuecomment-257753269"""
def __init__(self):
self.collected = []
def pytest_collection_modifyitems(self, items):
for item in items:
self.collected.append(item.nodeid)
collector = CollectTestFunctionNames()
rv = pytest.main(["--collect-only", TESTS_PATH], plugins=[collector])
if rv == pytest.ExitCode.INTERRUPTED:
print("Failed to collect all tests, perhaps there is a syntax error in one of test files?")
sys.stdout.flush()
os._exit(1)
print("Listing collected tests:")
for nodeid in collector.collected:
print("Test:", nodeid)
# easy way to exit GDB session
sys.stdout.flush()
os._exit(0)