summaryrefslogtreecommitdiff
path: root/coverage/execfile.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2010-02-19 23:08:48 -0500
committerNed Batchelder <ned@nedbatchelder.com>2010-02-19 23:08:48 -0500
commitf70090edc42512d8c50d9629867645fff552b775 (patch)
tree4c1e312bb2d61a3fabaf5c69f3dcab24c8ae6302 /coverage/execfile.py
parent34f71934dacede93f59b372fde4c5a646dbc702b (diff)
downloadpython-coveragepy-f70090edc42512d8c50d9629867645fff552b775.tar.gz
If the product code throws an exception, 'coverage run' now produces the same traceback as 'python' would, without the coverage-internal frames distracting from your code.
Diffstat (limited to 'coverage/execfile.py')
-rw-r--r--coverage/execfile.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/coverage/execfile.py b/coverage/execfile.py
index 15f0a5f..f04840b 100644
--- a/coverage/execfile.py
+++ b/coverage/execfile.py
@@ -3,7 +3,7 @@
import imp, os, sys
from coverage.backward import exec_function
-from coverage.misc import NoSource
+from coverage.misc import NoSource, ExceptionDuringRun
try:
@@ -36,11 +36,23 @@ def run_python_file(filename, args):
sys.path[0] = os.path.dirname(filename)
try:
+ # Open the source file.
try:
source = open(filename, 'rU').read()
except IOError:
raise NoSource("No file to run: %r" % filename)
- exec_function(source, filename, main_mod.__dict__)
+
+ # Execute the source file.
+ try:
+ exec_function(source, filename, main_mod.__dict__)
+ except:
+ # Something went wrong while executing the user code.
+ # Get the exc_info, and pack them into an exception that we can
+ # throw up to the outer loop. We peel two layers off the traceback
+ # so that the coverage.py code doesn't appear in the final printed
+ # traceback.
+ typ, err, tb = sys.exc_info()
+ raise ExceptionDuringRun(typ, err, tb.tb_next.tb_next)
finally:
# Restore the old __main__
sys.modules['__main__'] = old_main_mod