summaryrefslogtreecommitdiff
path: root/numpy/testing/utils.py
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2016-06-19 13:12:54 +0200
committerSebastian Berg <sebastian@sipsolutions.net>2016-09-02 10:10:55 +0200
commit968507bdfb4467d5ec6e3b6999a5717100782c3c (patch)
treeb79fa7fbb18064f56a0605e6436a91342fb8be7c /numpy/testing/utils.py
parent29a45efa15cf3992ab01b1535d51189319a7592d (diff)
downloadnumpy-968507bdfb4467d5ec6e3b6999a5717100782c3c.tar.gz
ENH: Make warning testing context managers more specific
This means that warnings of different origin then the one tested for behave normally. If the normal behaviour is to igonre them this might decrease specificity in rare cases. In most cases the specificity will be slightly higher.
Diffstat (limited to 'numpy/testing/utils.py')
-rw-r--r--numpy/testing/utils.py11
1 files changed, 3 insertions, 8 deletions
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py
index c7f4a0aa7..8789dd13c 100644
--- a/numpy/testing/utils.py
+++ b/numpy/testing/utils.py
@@ -1658,16 +1658,12 @@ class WarningManager(object):
@contextlib.contextmanager
def _assert_warns_context(warning_class, name=None):
__tracebackhide__ = True # Hide traceback for py.test
- with warnings.catch_warnings(record=True) as l:
- warnings.simplefilter('always')
+ with suppress_warnings() as sup:
+ l = sup.record(warning_class)
yield
if not len(l) > 0:
name_str = " when calling %s" % name if name is not None else ""
raise AssertionError("No warning raised" + name_str)
- if not l[0].category is warning_class:
- name_str = "%s " % name if name is not None else ""
- raise AssertionError("First warning %sis not a %s (is %s)"
- % (name_str, warning_class, l[0]))
def assert_warns(warning_class, *args, **kwargs):
@@ -1676,8 +1672,7 @@ def assert_warns(warning_class, *args, **kwargs):
A warning of class warning_class should be thrown by the callable when
invoked with arguments args and keyword arguments kwargs.
- If a different type of warning is thrown, it will not be caught, and the
- test case will be deemed to have suffered an error.
+ If a different type of warning is thrown, it will not be caught.
If called with all arguments other than the warning class omitted, may be
used as a context manager: