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("""