Skip to content

Commit

Permalink
Pass exitstatus to pytest_terminal_summary hook
Browse files Browse the repository at this point in the history
This is useful to know if a testrun has been interrupted
(EXIT_INTERRUPTED).
  • Loading branch information
blueyed committed Aug 14, 2016
1 parent 99a4a1a commit 5b95ee3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion _pytest/hookspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. """


Expand Down
3 changes: 2 additions & 1 deletion _pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: {0}".format(exitstatus))
""")
result = testdir.runpytest()
result.stdout.fnmatch_lines("""
*==== hello ====*
world
exitstatus: 5
""")


Expand Down

0 comments on commit 5b95ee3

Please sign in to comment.