From 836c9f82f12b8d2558d2b3a70edb6b53a6d2d5ac Mon Sep 17 00:00:00 2001 From: Jose Carlos Menezes Date: Sun, 14 Oct 2018 16:39:43 -0300 Subject: [PATCH] Set test session exitstatus value from Exit excetion return code --- src/_pytest/main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/_pytest/main.py b/src/_pytest/main.py index 0171bda0c..c1896cdfa 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -185,10 +185,12 @@ def wrap_session(config, doit): session.exitstatus = EXIT_TESTSFAILED except KeyboardInterrupt: excinfo = _pytest._code.ExceptionInfo() - if initstate < 2 and isinstance(excinfo.value, exit.Exception): + exitstatus = EXIT_INTERRUPTED + if initstate <= 2 and isinstance(excinfo.value, exit.Exception): sys.stderr.write("{}: {}\n".format(excinfo.typename, excinfo.value.msg)) + exitstatus = excinfo.value.returncode config.hook.pytest_keyboard_interrupt(excinfo=excinfo) - session.exitstatus = EXIT_INTERRUPTED + session.exitstatus = exitstatus except: # noqa excinfo = _pytest._code.ExceptionInfo() config.notify_exception(excinfo, config.option)