Handle Exit exception in pytest_sessionfinish
Similar to a7268aa (https://github.com/pytest-dev/pytest/pull/6258).
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
from typing import Optional
|
||||
|
||||
import pytest
|
||||
from _pytest.main import ExitCode
|
||||
from _pytest.pytester import Testdir
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -50,3 +53,25 @@ def test_wrap_session_notify_exception(ret_exc, testdir):
|
||||
assert result.stderr.lines == ["mainloop: caught unexpected SystemExit!"]
|
||||
else:
|
||||
assert result.stderr.lines == ["Exit: exiting after {}...".format(exc.__name__)]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("returncode", (None, 42))
|
||||
def test_wrap_session_exit_sessionfinish(
|
||||
returncode: Optional[int], testdir: Testdir
|
||||
) -> None:
|
||||
testdir.makeconftest(
|
||||
"""
|
||||
import pytest
|
||||
def pytest_sessionfinish():
|
||||
pytest.exit(msg="exit_pytest_sessionfinish", returncode={returncode})
|
||||
""".format(
|
||||
returncode=returncode
|
||||
)
|
||||
)
|
||||
result = testdir.runpytest()
|
||||
if returncode:
|
||||
assert result.ret == returncode
|
||||
else:
|
||||
assert result.ret == ExitCode.NO_TESTS_COLLECTED
|
||||
assert result.stdout.lines[-1] == "collected 0 items"
|
||||
assert result.stderr.lines == ["Exit: exit_pytest_sessionfinish"]
|
||||
|
||||
Reference in New Issue
Block a user