[New-bugs-announce] [issue29130] Exit code 120 returned from Python unit test testing SystemExit

John Hagen report at bugs.python.org
Sun Jan 1 19:28:18 EST 2017

New submission from John Hagen:

I recently tried to port one of my packages to Python 3.6 and unit tests that worked in Python 2.7, 3.3-3.5 began failing in 3.6.

I originally thought it was a problem with coverage, but it turns out it was not. The full thread is: https://bitbucket.org/ned/coveragepy/issues/545/coverage-fails-on-python-36-travis-build

The highlight is this unit test causes Python to exit with status code 120 (which fails a Travis build):

class ParseArgumentsTestCase(unittest.TestCase):
    def test_no_arguments(self):  # type: () -> None
        with self.assertRaises(SystemExit):
            # Suppress argparse stderr.
            class NullWriter:
                def write(self, s):  # type: (str) -> None

            sys.stderr = NullWriter()

Ned found this corresponding note in the Python 3.6 release notes:

Changed in version 3.6: If an error occurs in the cleanup after the Python interpreter has caught SystemExit (such as an error flushing buffered data in the standard streams), the exit status is changed to 120.

If this is indeed, correct behavior and Python 3.6 is catching something incorrect (I agree this is not necessarily the most elegant unit test) then I am happy to close this issue. Just wanted to be sure I at least reported it in case this was a real issue.

components: IO
messages: 284437
nosy: John Hagen
priority: normal
severity: normal
status: open
title: Exit code 120 returned from Python unit test testing SystemExit
type: behavior
versions: Python 3.6

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list