summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2010-02-24 20:59:45 -0500
committerNed Batchelder <ned@nedbatchelder.com>2010-02-24 20:59:45 -0500
commit641b53b96bccb763beb2ad257ff3d6593cf27fec (patch)
treeb8d24fec99f31c83c8eb3f6a423fa6161fe9ab5e
parent1db860fe7412fb5bda5857c41ae73e6efde71616 (diff)
downloadpython-coveragepy-git-641b53b96bccb763beb2ad257ff3d6593cf27fec.tar.gz
When emulating the Python interpreter, don't print SystemExits tracebacks.
-rw-r--r--coverage/cmdline.py7
-rw-r--r--test/test_process.py19
2 files changed, 25 insertions, 1 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py
index 0ab74759..c9383689 100644
--- a/coverage/cmdline.py
+++ b/coverage/cmdline.py
@@ -598,8 +598,13 @@ def main():
try:
status = CoverageScript().command_line(sys.argv[1:])
except ExceptionDuringRun:
+ # An exception was caught while running the product code. The
+ # sys.exc_info() return tuple is packed into an ExceptionDuringRun
+ # exception. Note that the Python interpreter doesn't print SystemExit
+ # tracebacks, so it's important that we don't also.
_, err, _ = sys.exc_info()
- traceback.print_exception(*err.args)
+ if not isinstance(err.args[1], SystemExit):
+ traceback.print_exception(*err.args)
status = ERR
except CoverageException:
_, err, _ = sys.exc_info()
diff --git a/test/test_process.py b/test/test_process.py
index 8e621adf..53dce065 100644
--- a/test/test_process.py
+++ b/test/test_process.py
@@ -170,3 +170,22 @@ class ProcessTest(CoverageTest):
self.assertTrue('File "throw.py", line 5, in f2' in out)
self.assertTrue('raise Exception("hey!")' in out)
self.assertFalse('coverage' in out)
+
+ def test_code_exits(self):
+ self.make_file("exit.py", """\
+ import sys
+ def f1():
+ print("about to exit..")
+ sys.exit(17)
+
+ def f2():
+ f1()
+
+ f2()
+ """)
+
+ # The important thing is for "coverage run" and "python" to report the
+ # same traceback.
+ out = self.run_command("coverage run exit.py")
+ out2 = self.run_command("python exit.py")
+ self.assertMultiLineEqual(out, out2)