Skip to content

Commit 205aa3d

Browse files
committed
PR Feedback 2
1 parent 2e170ae commit 205aa3d

2 files changed

Lines changed: 48 additions & 45 deletions

File tree

sqlmesh/core/test/__init__.py

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,57 +21,16 @@
2121
load_model_test_file as load_model_test_file,
2222
)
2323
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+
)
2528
from sqlmesh.utils import UniqueKeyDict, Verbosity
2629

2730
if t.TYPE_CHECKING:
2831
from sqlmesh.core.config.loader import C
2932

3033

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-
7534
def run_tests(
7635
model_test_metadata: list[ModelTestMetadata],
7736
models: UniqueKeyDict[str, Model],

sqlmesh/core/test/runner.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,47 @@ def __init__(
2020
resultclass=ModelTextTestResult,
2121
**kwargs,
2222
)
23+
24+
25+
def log_test_report(results: ModelTextTestResult, test_duration: float) -> None:
26+
# Aggregate parallel test run results
27+
tests_run = results.testsRun
28+
errors = results.errors
29+
failures = results.failures
30+
skipped = results.skipped
31+
32+
is_success = not (errors or failures)
33+
34+
# Compute test info
35+
infos = []
36+
if failures:
37+
infos.append(f"failures={len(failures)}")
38+
if errors:
39+
infos.append(f"errors={len(errors)}")
40+
if skipped:
41+
infos.append(f"skipped={skipped}")
42+
43+
# Report test errors
44+
stream = results.stream
45+
46+
stream.write("\n")
47+
48+
for test_case, err in failures:
49+
stream.writeln(unittest.TextTestResult.separator1)
50+
stream.writeln(f"FAIL: {test_case}")
51+
stream.writeln(unittest.TextTestResult.separator2)
52+
stream.writeln(err)
53+
54+
for error in errors:
55+
stream.writeln(unittest.TextTestResult.separator1)
56+
stream.writeln(f"ERROR: {error[1]}")
57+
stream.writeln(unittest.TextTestResult.separator2)
58+
59+
# Test report
60+
stream.writeln(unittest.TextTestResult.separator2)
61+
stream.writeln(
62+
f'Ran {tests_run} {"tests" if tests_run > 1 else "test"} in {test_duration:.3f}s \n'
63+
)
64+
stream.writeln(
65+
f'{"OK" if is_success else "FAILED"}{" (" + ", ".join(infos) + ")" if infos else ""}'
66+
)

0 commit comments

Comments
 (0)