Skip to content

Commit

Permalink
Suppress traceback for model tests (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
vchan authored Feb 20, 2023
1 parent b424ee0 commit 692d160
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion sqlmesh/core/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import fnmatch
import itertools
import pathlib
import types
import typing as t
import unittest

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


class ModelTextTestResult(unittest.TextTestResult):
def addFailure(
self,
test: unittest.TestCase,
err: t.Union[
t.Tuple[t.Type[BaseException], BaseException, types.TracebackType],
t.Tuple[None, None, None],
],
) -> None:
"""Called when the test case test signals a failure.
The traceback is suppressed because it is redundant and not useful.
Args:
test: The test case.
err: A tuple of the form returned by sys.exc_info(), i.e., (type, value, traceback).
"""
exctype, value, tb = err
return super().addFailure(test, (exctype, value, None)) # type: ignore


def load_model_test_file(
path: pathlib.Path,
) -> t.Dict[str, ModelTestMetadata]:
Expand Down Expand Up @@ -254,7 +276,7 @@ def run_tests(
)
for metadata in model_test_metadata
)
return unittest.TextTestRunner(verbosity=verbosity).run(suite)
return unittest.TextTestRunner(verbosity=verbosity, resultclass=ModelTextTestResult).run(suite)


def get_all_model_tests(
Expand Down

0 comments on commit 692d160

Please sign in to comment.