Merge pull request #4229 from nicoddemus/fix-warning-location

Show node that originated a warning in the warnings summary
This commit is contained in:
Ronny Pfannschmidt 2018-10-25 08:26:01 +02:00 committed by GitHub
commit f6dfca7182
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 5 deletions

View File

@ -0,0 +1 @@
Fix bug where the warning summary at the end of the test session was not showing the test where the warning was originated.

View File

@ -725,11 +725,10 @@ class TerminalReporter(object):
# legacy warnings show their location explicitly, while standard warnings look better without
# it because the location is already formatted into the message
warning_records = list(warning_records)
is_legacy = warning_records[0].legacy
if location and is_legacy:
if location:
self._tw.line(str(location))
for w in warning_records:
if is_legacy:
if location:
lines = w.message.splitlines()
indented = "\n".join(" " + x for x in lines)
message = indented.rstrip()

View File

@ -48,6 +48,7 @@ def test_normal_flow(testdir, pyfile_with_warnings):
result.stdout.fnmatch_lines(
[
"*== %s ==*" % WARNINGS_SUMMARY_HEADER,
"test_normal_flow.py::test_func",
"*normal_flow_module.py:3: UserWarning: user warning",
'* warnings.warn(UserWarning("user warning"))',
"*normal_flow_module.py:4: RuntimeWarning: runtime warning",