Commit c823c4f6 authored by Antoine Pitrou's avatar Antoine Pitrou

Make check_warnings error messages more informative

parent a4c197df
...@@ -596,22 +596,22 @@ def _filterwarnings(filters, quiet=False): ...@@ -596,22 +596,22 @@ def _filterwarnings(filters, quiet=False):
sys.modules['warnings'].simplefilter("always") sys.modules['warnings'].simplefilter("always")
yield WarningsRecorder(w) yield WarningsRecorder(w)
# Filter the recorded warnings # Filter the recorded warnings
reraise = [warning.message for warning in w] reraise = list(w)
missing = [] missing = []
for msg, cat in filters: for msg, cat in filters:
seen = False seen = False
for exc in reraise[:]: for w in reraise[:]:
message = str(exc) warning = w.message
# Filter out the matching messages # Filter out the matching messages
if (re.match(msg, message, re.I) and if (re.match(msg, str(warning), re.I) and
issubclass(exc.__class__, cat)): issubclass(warning.__class__, cat)):
seen = True seen = True
reraise.remove(exc) reraise.remove(w)
if not seen and not quiet: if not seen and not quiet:
# This filter caught nothing # This filter caught nothing
missing.append((msg, cat.__name__)) missing.append((msg, cat.__name__))
if reraise: if reraise:
raise AssertionError("unhandled warning %r" % reraise[0]) raise AssertionError("unhandled warning %s" % reraise[0])
if missing: if missing:
raise AssertionError("filter (%r, %s) did not catch any warning" % raise AssertionError("filter (%r, %s) did not catch any warning" %
missing[0]) missing[0])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment