-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconftest.py
62 lines (45 loc) · 1.84 KB
/
conftest.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import sys
import pytest
# This collects tests that aren't standard pytest tests
def pytest_collect_file(parent, file_path):
# Special handling for test_validation.py
if file_path.name == "test_validation.py":
return ValidationTestFile.from_parent(parent, path=file_path)
return None
class ValidationTestFile(pytest.File):
def collect(self):
# Create a special test item for test_validation.py
yield ValidationTestItem.from_parent(self, name="test_validation")
class ValidationTestItem(pytest.Item):
def runtest(self):
# Run the test_validation.py script with "schema" as the argument
import subprocess
print(f"\n{'-' * 80}\nRunning test_validation.py with 'schema' argument...")
result = subprocess.run(
[sys.executable, str(self.fspath), "schema"],
capture_output=True,
text=True,
)
# Always print the stdout for visibility
if result.stdout:
print(f"\nOutput from test_validation.py:")
print(result.stdout)
if result.returncode != 0:
raise ValidationTestFailure(result.stdout, result.stderr)
print(f"test_validation.py completed successfully.\n{'-' * 80}")
def reportinfo(self):
return self.fspath, 0, f"test_validation.py schema"
class ValidationTestFailure(Exception):
def __init__(self, stdout, stderr):
self.stdout = stdout
self.stderr = stderr
super().__init__(f"test_validation.py failed")
@pytest.hookimpl(tryfirst=True)
def pytest_exception_interact(node, call, report):
if isinstance(call.excinfo.value, ValidationTestFailure):
failure = call.excinfo.value
print(f"test_validation.py failed!")
if failure.stderr:
print(f"STDERR:\n{failure.stderr}")
print(f"{'-' * 80}")