diff options
Diffstat (limited to 'tests/test_unit.py')
| -rw-r--r-- | tests/test_unit.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/tests/test_unit.py b/tests/test_unit.py index cdb9691..975b65b 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -101,13 +101,29 @@ class TestCase(unittest.TestCase): if getattr(ar, "exception", None) is not None: print( - f"Raised expected exception: {type(ar.exception).__name__}: {str(ar.exception)}" + f"Raised expected exception: {type(ar.exception).__name__}: {ar.exception}" ) else: print(f"Expected {expected_exception_type.__name__} exception not raised") return ar @contextlib.contextmanager + def assertWarns(self, expected_warning_type: Any, msg: Any = None): + """ + Simple wrapper to print out the warnings raised after assertWarns + """ + with super().assertWarns(expected_warning_type, msg=msg) as ar: + yield + + if getattr(ar, "warning", None) is not None: + print( + f"Raised expected warning: {type(ar.warning).__name__}: {ar.warning}" + ) + else: + print(f"Expected {expected_warning_type.__name__} warning not raised") + return ar + + @contextlib.contextmanager def assertDoesNotWarn(self, warning_type: type = UserWarning, msg: str = None): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("error") |
