summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Oliveira <nicoddemus@gmail.com>2018-10-24 17:33:50 -0300
committerBruno Oliveira <nicoddemus@gmail.com>2018-10-24 18:49:53 -0300
commit2ad43ee442571f685c91b5d23792ae9d31d5e12f (patch)
tree7c799d9b47ea0e9760a9c41996d6a16b35923a01
parent15278aacb9debc077be032ce1231e7365caa59f0 (diff)
downloadpytest-2ad43ee442571f685c91b5d23792ae9d31d5e12f.tar.gz
Show node that originated a warning in the warnings summary
Fix #4221
-rw-r--r--changelog/4221.bugfix.rst1
-rw-r--r--src/_pytest/terminal.py5
-rw-r--r--testing/test_warnings.py5
3 files changed, 6 insertions, 5 deletions
diff --git a/changelog/4221.bugfix.rst b/changelog/4221.bugfix.rst
new file mode 100644
index 000000000..f55722f1c
--- /dev/null
+++ b/changelog/4221.bugfix.rst
@@ -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.
diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py
index 8deb330cc..37186a121 100644
--- a/src/_pytest/terminal.py
+++ b/src/_pytest/terminal.py
@@ -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()
diff --git a/testing/test_warnings.py b/testing/test_warnings.py
index 10eb5ea33..569414300 100644
--- a/testing/test_warnings.py
+++ b/testing/test_warnings.py
@@ -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",
@@ -369,8 +370,8 @@ def test_collection_warnings(testdir):
result.stdout.fnmatch_lines(
[
"*== %s ==*" % WARNINGS_SUMMARY_HEADER,
- "*collection_warnings.py:3: UserWarning: collection warning",
- ' warnings.warn(UserWarning("collection warning"))',
+ " *collection_warnings.py:3: UserWarning: collection warning",
+ ' warnings.warn(UserWarning("collection warning"))',
"* 1 passed, 1 warnings*",
]
)