summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2010-09-18 19:11:15 -0400
committerNed Batchelder <ned@nedbatchelder.com>2010-09-18 19:11:15 -0400
commit43a2b30a875e14bdead28bbd819548d09e2bce8c (patch)
tree8932f503d9479abd6ecc7faa9494c4df995680ed
parentd841d4604223d8ed3db3777750a397d0c4dafd15 (diff)
downloadpython-coveragepy-git-43a2b30a875e14bdead28bbd819548d09e2bce8c.tar.gz
If you called sys.exit() with no argument, coverage.py got tangled. Thanks, Brodie Rao.
-rw-r--r--CHANGES.txt3
-rw-r--r--coverage/cmdline.py7
-rw-r--r--test/test_process.py17
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", """\