report keyboardintterupt even if inteerrupted during sessionstartup
This commit is contained in:
parent
c25ea2cbe2
commit
d1684e8052
|
@ -15,6 +15,7 @@ Changes between 2.0.3 and 2.1.0.DEV
|
||||||
- fix issue44: env/username expansion for junitxml file path
|
- fix issue44: env/username expansion for junitxml file path
|
||||||
- show releaselevel information in test runs for pypy
|
- show releaselevel information in test runs for pypy
|
||||||
- reworked doc pages for better navigation and PDF generation
|
- reworked doc pages for better navigation and PDF generation
|
||||||
|
- report KeyboardInterrupt even if interrupted during session startup
|
||||||
|
|
||||||
Changes between 2.0.2 and 2.0.3
|
Changes between 2.0.2 and 2.0.3
|
||||||
----------------------------------------------
|
----------------------------------------------
|
||||||
|
|
|
@ -318,12 +318,17 @@ class TerminalReporter:
|
||||||
self.config.hook.pytest_terminal_summary(terminalreporter=self)
|
self.config.hook.pytest_terminal_summary(terminalreporter=self)
|
||||||
if exitstatus == 2:
|
if exitstatus == 2:
|
||||||
self._report_keyboardinterrupt()
|
self._report_keyboardinterrupt()
|
||||||
|
del self._keyboardinterrupt_memo
|
||||||
self.summary_deselected()
|
self.summary_deselected()
|
||||||
self.summary_stats()
|
self.summary_stats()
|
||||||
|
|
||||||
def pytest_keyboard_interrupt(self, excinfo):
|
def pytest_keyboard_interrupt(self, excinfo):
|
||||||
self._keyboardinterrupt_memo = excinfo.getrepr(funcargs=True)
|
self._keyboardinterrupt_memo = excinfo.getrepr(funcargs=True)
|
||||||
|
|
||||||
|
def pytest_unconfigure(self):
|
||||||
|
if hasattr(self, '_keyboardinterrupt_memo'):
|
||||||
|
self._report_keyboardinterrupt()
|
||||||
|
|
||||||
def _report_keyboardinterrupt(self):
|
def _report_keyboardinterrupt(self):
|
||||||
excrepr = self._keyboardinterrupt_memo
|
excrepr = self._keyboardinterrupt_memo
|
||||||
msg = excrepr.reprcrash.message
|
msg = excrepr.reprcrash.message
|
||||||
|
|
|
@ -167,6 +167,19 @@ class TestTerminal:
|
||||||
])
|
])
|
||||||
result.stdout.fnmatch_lines(['*KeyboardInterrupt*'])
|
result.stdout.fnmatch_lines(['*KeyboardInterrupt*'])
|
||||||
|
|
||||||
|
def test_keyboard_in_sessionstart(self, testdir):
|
||||||
|
testdir.makeconftest("""
|
||||||
|
def pytest_sessionstart():
|
||||||
|
raise KeyboardInterrupt
|
||||||
|
""")
|
||||||
|
p = testdir.makepyfile("""
|
||||||
|
def test_foobar():
|
||||||
|
pass
|
||||||
|
""")
|
||||||
|
|
||||||
|
result = testdir.runpytest()
|
||||||
|
assert result.ret == 2
|
||||||
|
result.stdout.fnmatch_lines(['*KeyboardInterrupt*'])
|
||||||
|
|
||||||
|
|
||||||
class TestCollectonly:
|
class TestCollectonly:
|
||||||
|
|
Loading…
Reference in New Issue