diff options
Diffstat (limited to 'coverage/execfile.py')
-rw-r--r-- | coverage/execfile.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/coverage/execfile.py b/coverage/execfile.py index 333163f8..8fbf63b8 100644 --- a/coverage/execfile.py +++ b/coverage/execfile.py @@ -38,10 +38,15 @@ def run_python_file(filename, args): try: # Open the source file. try: - source = open(filename, 'rU').read() + source_file = open(filename, 'rU') 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': |