|
2 | 2 | import fnmatch |
3 | 3 | import itertools |
4 | 4 | import pathlib |
| 5 | +import types |
5 | 6 | import typing as t |
6 | 7 | import unittest |
7 | 8 |
|
@@ -164,6 +165,27 @@ def _raise_error(self, msg: str) -> None: |
164 | 165 | raise TestError(f"{msg} at {self.path}") |
165 | 166 |
|
166 | 167 |
|
| 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 | + |
167 | 189 | def load_model_test_file( |
168 | 190 | path: pathlib.Path, |
169 | 191 | ) -> t.Dict[str, ModelTestMetadata]: |
@@ -254,7 +276,7 @@ def run_tests( |
254 | 276 | ) |
255 | 277 | for metadata in model_test_metadata |
256 | 278 | ) |
257 | | - return unittest.TextTestRunner(verbosity=verbosity).run(suite) |
| 279 | + return unittest.TextTestRunner(verbosity=verbosity, resultclass=ModelTextTestResult).run(suite) |
258 | 280 |
|
259 | 281 |
|
260 | 282 | def get_all_model_tests( |
|
0 commit comments