From d7be039f1b6ed1f3aaf04283a50e4601c25d1115 Mon Sep 17 00:00:00 2001 From: Jose Carlos Menezes Date: Sun, 14 Oct 2018 12:18:49 -0300 Subject: [PATCH] Add returncode argument to pytest.exit If the argument is not None, it'll raise a SystemExit exception to cleanly exit pytest. --- src/_pytest/outcomes.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/_pytest/outcomes.py b/src/_pytest/outcomes.py index f6093ef76..a220b2cd1 100644 --- a/src/_pytest/outcomes.py +++ b/src/_pytest/outcomes.py @@ -57,10 +57,13 @@ class Exit(KeyboardInterrupt): # exposed helper methods -def exit(msg): +def exit(msg, returncode=None): """ exit testing process as if KeyboardInterrupt was triggered. """ __tracebackhide__ = True - raise Exit(msg) + if returncode: + raise SystemExit(returncode) + else: + raise Exit(msg) exit.Exception = Exit