From ce55dcf64c31272ed8fff4c6f118af1956f3d0b3 Mon Sep 17 00:00:00 2001 From: Jose Carlos Menezes Date: Sun, 14 Oct 2018 12:20:10 -0300 Subject: [PATCH] Add test for calling pytest.exit with statuscode It checks that a SystemError was raised and the SystemError code is the same as the returncode argument. --- testing/test_runner.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/testing/test_runner.py b/testing/test_runner.py index b9538cfad..f9b7f8180 100644 --- a/testing/test_runner.py +++ b/testing/test_runner.py @@ -570,6 +570,15 @@ def test_pytest_exit_msg(testdir): result.stderr.fnmatch_lines(["Exit: oh noes"]) +def test_pytest_exit_returncode(): + try: + pytest.exit("hello", returncode=2) + except SystemExit as exc: + excinfo = _pytest._code.ExceptionInfo() + assert excinfo.errisinstance(SystemExit) + assert excinfo.value.code == 2 + + def test_pytest_fail_notrace_runtest(testdir): """Test pytest.fail(..., pytrace=False) does not show tracebacks during test run.""" testdir.makepyfile(