Skip to content

Commit 669e236

Browse files
committed
Move log_test_report to result class
1 parent 7f98b34 commit 669e236

2 files changed

Lines changed: 48 additions & 46 deletions

File tree

sqlmesh/core/test/result.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,50 @@ def addSuccess(self, test: unittest.TestCase) -> None:
7272
"""
7373
super().addSuccess(test)
7474
self.successes.append(test)
75+
76+
def log_test_report(self, test_duration: float) -> None:
77+
"""
78+
Log the test report following unittest's conventions.
79+
80+
Args:
81+
test_duration: The duration of the tests.
82+
"""
83+
tests_run = self.testsRun
84+
errors = self.errors
85+
failures = self.failures
86+
skipped = self.skipped
87+
88+
is_success = not (errors or failures)
89+
90+
infos = []
91+
if failures:
92+
infos.append(f"failures={len(failures)}")
93+
if errors:
94+
infos.append(f"errors={len(errors)}")
95+
if skipped:
96+
infos.append(f"skipped={skipped}")
97+
98+
stream = self.stream
99+
100+
stream.write("\n")
101+
102+
for test_case, failure in failures:
103+
stream.writeln(unittest.TextTestResult.separator1)
104+
stream.writeln(f"FAIL: {test_case}")
105+
stream.writeln(f"{test_case.shortDescription()}")
106+
stream.writeln(unittest.TextTestResult.separator2)
107+
stream.writeln(failure)
108+
109+
for _, error in errors:
110+
stream.writeln(unittest.TextTestResult.separator1)
111+
stream.writeln(f"ERROR: {error}")
112+
stream.writeln(unittest.TextTestResult.separator2)
113+
114+
# Output final report
115+
stream.writeln(unittest.TextTestResult.separator2)
116+
stream.writeln(
117+
f'Ran {tests_run} {"tests" if tests_run > 1 else "test"} in {test_duration:.3f}s \n'
118+
)
119+
stream.writeln(
120+
f'{"OK" if is_success else "FAILED"}{" (" + ", ".join(infos) + ")" if infos else ""}'
121+
)

sqlmesh/core/test/runner.py

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -45,51 +45,6 @@ def __init__(
4545
)
4646

4747

48-
def log_test_report(results: ModelTextTestResult, test_duration: float) -> None:
49-
# Aggregate parallel test run results
50-
tests_run = results.testsRun
51-
errors = results.errors
52-
failures = results.failures
53-
skipped = results.skipped
54-
55-
is_success = not (errors or failures)
56-
57-
# Compute test info
58-
infos = []
59-
if failures:
60-
infos.append(f"failures={len(failures)}")
61-
if errors:
62-
infos.append(f"errors={len(errors)}")
63-
if skipped:
64-
infos.append(f"skipped={skipped}")
65-
66-
# Report test errors
67-
stream = results.stream
68-
69-
stream.write("\n")
70-
71-
for test_case, failure in failures:
72-
stream.writeln(unittest.TextTestResult.separator1)
73-
stream.writeln(f"FAIL: {test_case}")
74-
stream.writeln(f"{test_case.shortDescription()}")
75-
stream.writeln(unittest.TextTestResult.separator2)
76-
stream.writeln(failure)
77-
78-
for _, error in errors:
79-
stream.writeln(unittest.TextTestResult.separator1)
80-
stream.writeln(f"ERROR: {error}")
81-
stream.writeln(unittest.TextTestResult.separator2)
82-
83-
# Test report
84-
stream.writeln(unittest.TextTestResult.separator2)
85-
stream.writeln(
86-
f'Ran {tests_run} {"tests" if tests_run > 1 else "test"} in {test_duration:.3f}s \n'
87-
)
88-
stream.writeln(
89-
f'{"OK" if is_success else "FAILED"}{" (" + ", ".join(infos) + ")" if infos else ""}'
90-
)
91-
92-
9348
def create_test_engine_adapters(
9449
model_test_metadata: list[ModelTestMetadata],
9550
config: C,
@@ -232,7 +187,7 @@ def _run_single_test(
232187

233188
combined_results.testsRun = len(test_results)
234189

235-
log_test_report(combined_results, test_duration=end_time - start_time)
190+
combined_results.log_test_report(test_duration=end_time - start_time)
236191

237192
return combined_results
238193

0 commit comments

Comments
 (0)