diff --git a/changelog/3563.bugfix.rst b/changelog/3563.bugfix.rst new file mode 100644 index 00000000000..8ba24c5dda3 --- /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 a985ab22191..9c4eec7531a 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -682,7 +682,7 @@ def summary_warnings(self): 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 68ce51d43cc..8f08ad34fa1 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -1025,7 +1025,10 @@ def pytest_terminal_summary(terminalreporter): """ ) 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(