From 766d2daa06509839779cd2f33728535d2b428485 Mon Sep 17 00:00:00 2001 From: Jose Carlos Menezes Date: Sun, 14 Oct 2018 16:41:16 -0300 Subject: [PATCH] Update returncode exit test to check exitstatus returrned from test session --- testing/test_runner.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/testing/test_runner.py b/testing/test_runner.py index f9b7f8180..a3fffe81a 100644 --- a/testing/test_runner.py +++ b/testing/test_runner.py @@ -570,13 +570,16 @@ 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_exit_returncode(testdir): + testdir.makepyfile( + """ + import pytest + def test_foo(): + pytest.exit("some exit msg", 99) + """ + ) + result = testdir.runpytest() + assert result.ret == 99 def test_pytest_fail_notrace_runtest(testdir):