forked from pytest-dev/pytest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
main: wrap_session: handle exit.Exception with notify_exception
Fixes pytest-dev#6257. Via blueyed#132.
- Loading branch information
1 parent
2594786
commit 40ba953
Showing
3 changed files
with
63 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Handle `exit.Exception` raised in `notify_exception` (via `pytest_internalerror`), e.g. when quitting pdb from post mortem. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import pytest | ||
from _pytest.main import ExitCode | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"ret_exc", | ||
( | ||
pytest.param((None, ValueError)), | ||
pytest.param((42, SystemExit)), | ||
pytest.param((False, SystemExit)), | ||
), | ||
) | ||
def test_wrap_session_notify_exception(ret_exc, testdir): | ||
returncode, exc = ret_exc | ||
c1 = testdir.makeconftest( | ||
""" | ||
import pytest | ||
def pytest_sessionstart(): | ||
raise {exc}("boom") | ||
def pytest_internalerror(excrepr, excinfo): | ||
returncode = {returncode!r} | ||
if returncode is not False: | ||
pytest.exit("exiting after %s..." % excinfo.typename, returncode={returncode!r}) | ||
""".format( | ||
returncode=returncode, exc=exc.__name__ | ||
) | ||
) | ||
result = testdir.runpytest() | ||
if returncode: | ||
assert result.ret == returncode | ||
else: | ||
assert result.ret == ExitCode.INTERNAL_ERROR | ||
assert result.stdout.lines[0] == "INTERNALERROR> Traceback (most recent call last):" | ||
|
||
if exc == SystemExit: | ||
assert result.stdout.lines[-3:] == [ | ||
'INTERNALERROR> File "{}", line 4, in pytest_sessionstart'.format(c1), | ||
'INTERNALERROR> raise SystemExit("boom")', | ||
"INTERNALERROR> SystemExit: boom", | ||
] | ||
else: | ||
assert result.stdout.lines[-3:] == [ | ||
'INTERNALERROR> File "{}", line 4, in pytest_sessionstart'.format(c1), | ||
'INTERNALERROR> raise ValueError("boom")', | ||
"INTERNALERROR> ValueError: boom", | ||
] | ||
if returncode is False: | ||
assert result.stderr.lines == ["mainloop: caught unexpected SystemExit!"] | ||
else: | ||
assert result.stderr.lines == ["Exit: exiting after {}...".format(exc.__name__)] |