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 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(