|
21 | 21 | load_model_test_file as load_model_test_file, |
22 | 22 | ) |
23 | 23 | from sqlmesh.core.test.result import ModelTextTestResult as ModelTextTestResult |
24 | | -from sqlmesh.core.test.runner import ModelTextTestRunner as ModelTextTestRunner |
| 24 | +from sqlmesh.core.test.runner import ( |
| 25 | + ModelTextTestRunner, |
| 26 | + log_test_report, |
| 27 | +) |
25 | 28 | from sqlmesh.utils import UniqueKeyDict, Verbosity |
26 | 29 |
|
27 | 30 | if t.TYPE_CHECKING: |
28 | 31 | from sqlmesh.core.config.loader import C |
29 | 32 |
|
30 | 33 |
|
31 | | -def log_test_report(results: ModelTextTestResult, test_duration: float) -> None: |
32 | | - # Aggregate parallel test run results |
33 | | - tests_run = results.testsRun |
34 | | - errors = results.errors |
35 | | - failures = results.failures |
36 | | - skipped = results.skipped |
37 | | - |
38 | | - is_success = not (errors or failures) |
39 | | - |
40 | | - # Compute test info |
41 | | - infos = [] |
42 | | - if failures: |
43 | | - infos.append(f"failures={len(failures)}") |
44 | | - if errors: |
45 | | - infos.append(f"errors={len(errors)}") |
46 | | - if skipped: |
47 | | - infos.append(f"skipped={skipped}") |
48 | | - |
49 | | - # Report test errors |
50 | | - stream = results.stream |
51 | | - |
52 | | - stream.write("\n") |
53 | | - |
54 | | - for test_case, err in failures: |
55 | | - stream.writeln(unittest.TextTestResult.separator1) |
56 | | - stream.writeln(f"FAIL: {test_case}") |
57 | | - stream.writeln(unittest.TextTestResult.separator2) |
58 | | - stream.writeln(err) |
59 | | - |
60 | | - for error in errors: |
61 | | - stream.writeln(unittest.TextTestResult.separator1) |
62 | | - stream.writeln(f"ERROR: {error[1]}") |
63 | | - stream.writeln(unittest.TextTestResult.separator2) |
64 | | - |
65 | | - # Test report |
66 | | - stream.writeln(unittest.TextTestResult.separator2) |
67 | | - stream.writeln( |
68 | | - f'Ran {tests_run} {"tests" if tests_run > 1 else "test"} in {test_duration:.3f}s \n' |
69 | | - ) |
70 | | - stream.writeln( |
71 | | - f'{"OK" if is_success else "FAILED"}{" (" + ", ".join(infos) + ")" if infos else ""}' |
72 | | - ) |
73 | | - |
74 | | - |
75 | 34 | def run_tests( |
76 | 35 | model_test_metadata: list[ModelTestMetadata], |
77 | 36 | models: UniqueKeyDict[str, Model], |
|
0 commit comments