summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorptmcg <ptmcg@austin.rr.com>2022-11-06 17:24:52 -0600
committerptmcg <ptmcg@austin.rr.com>2022-11-06 17:24:52 -0600
commitc1d239103c0060212e59f99171ccc4d8405420eb (patch)
treebfe18fcc44c074991f47245c5241d1c4b73d24be /tests
parent764dbdc1970e522f5ffe3bd03a0ddb5d1cfcb798 (diff)
downloadpyparsing-git-c1d239103c0060212e59f99171ccc4d8405420eb.tar.gz
Fix stacklevel when warning invalid config setting; added assertWarns wrapper similar to assertRaises wrapper, to echo success/fail status
Diffstat (limited to 'tests')
-rw-r--r--tests/test_unit.py18
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")