summaryrefslogtreecommitdiff
path: root/coverage/execfile.py
diff options
context:
space:
mode:
Diffstat (limited to 'coverage/execfile.py')
-rw-r--r--coverage/execfile.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/coverage/execfile.py b/coverage/execfile.py
index 333163f..c61556a 100644
--- a/coverage/execfile.py
+++ b/coverage/execfile.py
@@ -2,7 +2,7 @@
import imp, os, sys
-from coverage.backward import exec_code_object
+from coverage.backward import exec_code_object, open_source
from coverage.misc import NoSource, ExceptionDuringRun
@@ -38,10 +38,15 @@ def run_python_file(filename, args):
try:
# Open the source file.
try:
- source = open(filename, 'rU').read()
+ source_file = open_source(filename)
except IOError:
raise NoSource("No file to run: %r" % filename)
+ try:
+ source = source_file.read()
+ finally:
+ source_file.close()
+
# We have the source. `compile` still needs the last line to be clean,
# so make sure it is, then compile a code object from it.
if source[-1] != '\n':