diff --git a/changelog/3563.bugfix.rst b/changelog/3563.bugfix.rst new file mode 100644 index 000000000..8ba24c5dd --- /dev/null +++ b/changelog/3563.bugfix.rst @@ -0,0 +1 @@ +Warnings without ``location`` were reported as ``None``. This is corrected to now report ````. diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index a985ab221..9c4eec753 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -682,7 +682,7 @@ class TerminalReporter(object): self.write_sep("=", "warnings summary", yellow=True, bold=False) for location, warning_records in grouped: - self._tw.line(str(location) or "") + self._tw.line(str(location) if location else "") for w in warning_records: lines = w.message.splitlines() indented = "\n".join(" " + x for x in lines) diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 68ce51d43..8f08ad34f 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -1025,7 +1025,10 @@ def test_terminal_summary_warnings_are_displayed(testdir): """ ) result = testdir.runpytest("-rw") - result.stdout.fnmatch_lines(["*internal warning", "*== 1 warnings in *"]) + result.stdout.fnmatch_lines( + ["", "*internal warning", "*== 1 warnings in *"] + ) + assert "None" not in result.stdout.str() @pytest.mark.parametrize(