Skip to content

Commit 692d160

Browse files
authored
Suppress traceback for model tests (#418)
1 parent b424ee0 commit 692d160

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

sqlmesh/core/test.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import fnmatch
33
import itertools
44
import pathlib
5+
import types
56
import typing as t
67
import unittest
78

@@ -164,6 +165,27 @@ def _raise_error(self, msg: str) -> None:
164165
raise TestError(f"{msg} at {self.path}")
165166

166167

168+
class ModelTextTestResult(unittest.TextTestResult):
169+
def addFailure(
170+
self,
171+
test: unittest.TestCase,
172+
err: t.Union[
173+
t.Tuple[t.Type[BaseException], BaseException, types.TracebackType],
174+
t.Tuple[None, None, None],
175+
],
176+
) -> None:
177+
"""Called when the test case test signals a failure.
178+
179+
The traceback is suppressed because it is redundant and not useful.
180+
181+
Args:
182+
test: The test case.
183+
err: A tuple of the form returned by sys.exc_info(), i.e., (type, value, traceback).
184+
"""
185+
exctype, value, tb = err
186+
return super().addFailure(test, (exctype, value, None)) # type: ignore
187+
188+
167189
def load_model_test_file(
168190
path: pathlib.Path,
169191
) -> t.Dict[str, ModelTestMetadata]:
@@ -254,7 +276,7 @@ def run_tests(
254276
)
255277
for metadata in model_test_metadata
256278
)
257-
return unittest.TextTestRunner(verbosity=verbosity).run(suite)
279+
return unittest.TextTestRunner(verbosity=verbosity, resultclass=ModelTextTestResult).run(suite)
258280

259281

260282
def get_all_model_tests(

0 commit comments

Comments
 (0)