From 49f621de767f3c1c84185a8198d016eb95a8cb1c Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sun, 10 Jun 2018 10:51:36 -0700 Subject: [PATCH] Print instead of None for warnings --- changelog/3563.bugfix.rst | 1 + src/_pytest/terminal.py | 2 +- testing/test_terminal.py | 5 ++++- 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 changelog/3563.bugfix.rst 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(