diff options
| -rw-r--r-- | pyparsing/util.py | 3 | ||||
| -rw-r--r-- | tests/test_unit.py | 18 |
2 files changed, 19 insertions, 2 deletions
diff --git a/pyparsing/util.py b/pyparsing/util.py index b3db48a..2a06e39 100644 --- a/pyparsing/util.py +++ b/pyparsing/util.py @@ -23,7 +23,8 @@ class __config_flags: if dname in cls._fixed_names: warnings.warn( f"{cls.__name__}.{dname} {cls._type_desc} is {str(getattr(cls, dname)).upper()}" - f" and cannot be overridden" + f" and cannot be overridden", + stacklevel=3, ) return if dname in cls._all_names: 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") |
