From 369d9ecaa52e6680cc05f58d60314719df751b47 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Mon, 4 Jan 2016 00:07:45 -0200 Subject: [PATCH 1/2] pytest warnings emitted during ``pytest_terminal_summary`` are now properly displayed. Fix #1305 --- CHANGELOG | 4 ++++ _pytest/terminal.py | 2 +- testing/test_terminal.py | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 439a6242a..4d62b18f5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -15,6 +15,10 @@ - fix #1292: monkeypatch calls (setattr, setenv, etc.) are now O(1). Thanks David R. MacIver for the report and Bruno Oliveira for the PR. +- fix #1305: pytest warnings emitted during ``pytest_terminal_summary`` are now + properly displayed. + Thanks Ionel Maries Cristian for the report and Bruno Oliveira for the PR. + 2.8.5 ----- diff --git a/_pytest/terminal.py b/_pytest/terminal.py index 8aca7dd92..dac134cd2 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -364,10 +364,10 @@ class TerminalReporter: EXIT_OK, EXIT_TESTSFAILED, EXIT_INTERRUPTED, EXIT_USAGEERROR, EXIT_NOTESTSCOLLECTED) if exitstatus in summary_exit_codes: + self.config.hook.pytest_terminal_summary(terminalreporter=self) self.summary_errors() self.summary_failures() self.summary_warnings() - self.config.hook.pytest_terminal_summary(terminalreporter=self) if exitstatus == EXIT_INTERRUPTED: self._report_keyboardinterrupt() del self._keyboardinterrupt_memo diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 7c4b3eba6..305d60ab8 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -739,6 +739,23 @@ def test_terminal_summary(testdir): world """) + +def test_terminal_summary_warnings_are_displayed(testdir): + """Test that warnings emitted during pytest_terminal_summary are displayed. + (#1305). + """ + testdir.makeconftest(""" + def pytest_terminal_summary(terminalreporter): + config = terminalreporter.config + config.warn('C1', 'internal warning') + """) + result = testdir.runpytest('-rw') + result.stdout.fnmatch_lines([ + '*C1*internal warning', + '*== 1 pytest-warnings in *', + ]) + + @pytest.mark.parametrize("exp_color, exp_line, stats_arg", [ # The method under test only cares about the length of each # dict value, not the actual contents, so tuples of anything From 26c835eea50265a9c96a08dec912067aafa6a6cc Mon Sep 17 00:00:00 2001 From: Kartik Singhal Date: Tue, 5 Jan 2016 18:43:03 -0500 Subject: [PATCH 2/2] Correct platform name osx -> darwin --- doc/en/example/markers.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/en/example/markers.rst b/doc/en/example/markers.rst index aaca80fb2..95554189b 100644 --- a/doc/en/example/markers.rst +++ b/doc/en/example/markers.rst @@ -436,7 +436,7 @@ marking platform specific tests with pytest .. regendoc:wipe Consider you have a test suite which marks tests for particular platforms, -namely ``pytest.mark.osx``, ``pytest.mark.win32`` etc. and you +namely ``pytest.mark.darwin``, ``pytest.mark.win32`` etc. and you also have tests that run on all platforms and have no specific marker. If you now want to have a way to only run the tests for your particular platform, you could use the following plugin:: @@ -446,7 +446,7 @@ for your particular platform, you could use the following plugin:: import sys import pytest - ALL = set("osx linux2 win32".split()) + ALL = set("darwin linux2 win32".split()) def pytest_runtest_setup(item): if isinstance(item, item.Function): @@ -462,7 +462,7 @@ Let's do a little test file to show how this looks like:: import pytest - @pytest.mark.osx + @pytest.mark.darwin def test_if_apple_is_evil(): pass