diff options
author | Daniel Hahler <git@thequod.de> | 2020-02-07 00:40:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-07 00:40:10 +0100 |
commit | a8fc056aad47070bbf60c266409f3eafd71c434c (patch) | |
tree | 112af502c4cfcd5e6fc7cb7457162dfb8750e1ca /testing | |
parent | ef437ea44831c949650376c24f925a023f4192db (diff) | |
parent | 99d162e44a0d40675b855dbcde9734b29032f8aa (diff) | |
download | pytest-a8fc056aad47070bbf60c266409f3eafd71c434c.tar.gz |
Handle `Exit` exception in `pytest_sessionfinish` (#6660)
Diffstat (limited to 'testing')
-rw-r--r-- | testing/test_main.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/testing/test_main.py b/testing/test_main.py index b47791b29..49e3decd0 100644 --- a/testing/test_main.py +++ b/testing/test_main.py @@ -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"] |