From 13f0b340c8b65a52f933c9aebf56ede6ba992c4b Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 14 Aug 2016 15:02:35 +0200 Subject: [PATCH] Pass exitstatus to pytest_terminal_summary hook This is useful to know if a testrun has been interrupted (EXIT_INTERRUPTED). --- _pytest/hookspec.py | 2 +- _pytest/terminal.py | 3 ++- testing/test_terminal.py | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/_pytest/hookspec.py b/_pytest/hookspec.py index 2c6d8ba5162..b5f51eccf50 100644 --- a/_pytest/hookspec.py +++ b/_pytest/hookspec.py @@ -269,7 +269,7 @@ def pytest_report_header(config, startdir): def pytest_report_teststatus(report): """ return result-category, shortletter and verbose word for reporting.""" -def pytest_terminal_summary(terminalreporter): +def pytest_terminal_summary(terminalreporter, exitstatus): """ add additional section in terminal summary reporting. """ diff --git a/_pytest/terminal.py b/_pytest/terminal.py index 863e69ce80b..fdbe4ec36d0 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -361,7 +361,8 @@ def pytest_sessionfinish(self, exitstatus): 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.config.hook.pytest_terminal_summary(terminalreporter=self, + exitstatus=exitstatus) self.summary_errors() self.summary_failures() self.summary_warnings() diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 84c5bc4ac49..1307a924fbf 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -787,15 +787,17 @@ def test_error_fixture(setup_error_fixture): def test_terminal_summary(testdir): testdir.makeconftest(""" - def pytest_terminal_summary(terminalreporter): + def pytest_terminal_summary(terminalreporter, exitstatus): w = terminalreporter w.section("hello") w.line("world") + w.line("exitstatus: {}".format(exitstatus)) """) result = testdir.runpytest() result.stdout.fnmatch_lines(""" *==== hello ====* world + exitstatus: 5 """)