diff options
-rw-r--r-- | CHANGES.txt | 3 | ||||
-rw-r--r-- | coverage/cmdline.py | 7 | ||||
-rw-r--r-- | test/test_process.py | 17 |
3 files changed, 25 insertions, 2 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 2e6cdf22..27b1f72b 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -8,6 +8,9 @@ Version 3.4 - The XML report is now sorted by package name, fixing `issue 88`_. +- Programs that exited with ``sys.exit()`` with no argument weren't handled + properly, producing a coverage.py stack trace. That is now fixed. + .. _issue 88: http://bitbucket.org/ned/coveragepy/issue/88/xml-report-lists-packages-in-random-order diff --git a/coverage/cmdline.py b/coverage/cmdline.py index f56cc4cb..e5d6bb84 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -652,7 +652,10 @@ def main(argv=None): print(err) status = ERR except SystemExit: - # The user called `sys.exit()`. Exit with their status code. + # The user called `sys.exit()`. Exit with their argument, if any. _, err, _ = sys.exc_info() - status = err.args[0] + if err.args: + status = err.args[0] + else: + status = None return status diff --git a/test/test_process.py b/test/test_process.py index 169bd7bf..bb255fe9 100644 --- a/test/test_process.py +++ b/test/test_process.py @@ -204,6 +204,23 @@ class ProcessTest(CoverageTest): self.assertEqual(status, status2) self.assertEqual(status, 17) + def test_code_exits_no_arg(self): + self.make_file("exit_none.py", """\ + import sys + def f1(): + print("about to exit quietly..") + sys.exit() + + f1() + """) + status, out = self.run_command_status("coverage run exit_none.py", 0) + status2, out2 = self.run_command_status("python exit_none.py", 0) + self.assertMultiLineEqual(out, out2) + self.assertMultiLineEqual(out, "about to exit quietly..\n") + self.assertEqual(status, status2) + self.assertEqual(status, 0) + + if hasattr(os, 'fork'): def test_fork(self): self.make_file("fork.py", """\ |