From 78fbb6b4138fbbb95f90a2c7d268c06c3daf8ef9 Mon Sep 17 00:00:00 2001 From: Kris Wilson Date: Thu, 6 Aug 2015 16:08:27 -0700 Subject: [PATCH] Remove unnecessary stderr print on SystemExit().code == None --- pex/pex.py | 2 +- tests/test_pex.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pex/pex.py b/pex/pex.py index 2744bb61d..826dc13e7 100644 --- a/pex/pex.py +++ b/pex/pex.py @@ -321,7 +321,7 @@ def execute(self): except SystemExit as se: # Print a SystemExit error message, avoiding a traceback in python3. # This must happen here, as sys.stderr is about to be torn down - if not isinstance(se.code, int): + if not isinstance(se.code, int) and se.code is not None: print(se.code, file=sys.stderr) raise finally: diff --git a/tests/test_pex.py b/tests/test_pex.py index 14bfa5454..39152135d 100644 --- a/tests/test_pex.py +++ b/tests/test_pex.py @@ -60,6 +60,14 @@ def test_pex_sys_exit_prints_non_numeric_value_no_traceback(): _test_sys_exit(sys_exit_arg, expected_output, 1) +def test_pex_sys_exit_doesnt_print_none(): + _test_sys_exit('', to_bytes(''), 0) + + +def test_pex_sys_exit_prints_objects(): + _test_sys_exit('Exception("derp")', to_bytes('derp\n'), 1) + + @pytest.mark.skipif('hasattr(sys, "pypy_version_info")') def test_pex_atexit_swallowing(): body = textwrap.dedent("""