summaryrefslogtreecommitdiff
path: root/passlib/tests/utils.py
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2012-03-11 18:37:49 -0400
committerEli Collins <elic@assurancetechnologies.com>2012-03-11 18:37:49 -0400
commit09b88be2e515ebeddaf64a0f15309b6a3f04416f (patch)
tree9868ccb551c5dfd6e36d95e1b90c70ca440d6b14 /passlib/tests/utils.py
parent29468d26fa3c68a56bd739d4dd9be50d8dd6725c (diff)
downloadpasslib-09b88be2e515ebeddaf64a0f15309b6a3f04416f.tar.gz
added hack to clear warnings registry so assertWarningList() tests will pass reliably
Diffstat (limited to 'passlib/tests/utils.py')
-rw-r--r--passlib/tests/utils.py31
1 files changed, 28 insertions, 3 deletions
diff --git a/passlib/tests/utils.py b/passlib/tests/utils.py
index fde0f87..c309bc4 100644
--- a/passlib/tests/utils.py
+++ b/passlib/tests/utils.py
@@ -628,11 +628,9 @@ class HandlerCase(TestCase):
def setUp(self):
# backup warning filter state; set to display all warnings during tests;
# and restore filter state after test.
- ctx = catch_warnings()
+ ctx = catch_all_warnings()
ctx.__enter__()
self._restore_warnings = ctx.__exit__
- warnings.resetwarnings()
- warnings.simplefilter("always")
# if needed, select specific backend for duration of test
handler = self.handler
@@ -1894,6 +1892,33 @@ except ImportError:
self._module.filters = self._filters
self._module.showwarning = self._showwarning
+class catch_all_warnings(catch_warnings):
+ "catch_warnings() wrapper which clears filter"
+ def __init__(self, reset=".*", **kwds):
+ super(catch_all_warnings, self).__init__(**kwds)
+ self._reset_pat = reset
+
+ def __enter__(self):
+ # let parent class archive filter state
+ ret = super(catch_all_warnings, self).__enter__()
+
+ # reset the filter to list everything
+ warnings.resetwarnings()
+ warnings.simplefilter("always")
+
+ # wipe the __warningregistry__ off the map, so warnings
+ # reliably get reported per-test.
+ # XXX: *could* restore state
+ pattern = self._reset_pat
+ if pattern:
+ import sys
+ key = "__warningregistry__"
+ for mod in sys.modules.values():
+ if hasattr(mod, key) and re.match(pattern, mod.__name__):
+ getattr(mod, key).clear()
+
+ return ret
+
#=========================================================
#EOF
#=========================================================