summaryrefslogtreecommitdiff
path: root/coverage/data.py
diff options
context:
space:
mode:
Diffstat (limited to 'coverage/data.py')
-rw-r--r--coverage/data.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/coverage/data.py b/coverage/data.py
index 26fee48..704a348 100644
--- a/coverage/data.py
+++ b/coverage/data.py
@@ -238,9 +238,13 @@ class CoverageData(object):
def _open_for_reading(cls, filename):
"""Open a file appropriately for reading data."""
f = open(filename, "r")
- go_away = f.read(len(cls.GO_AWAY))
- if go_away != cls.GO_AWAY:
- raise CoverageException("Doesn't seem to be a coverage.py data file")
+ try:
+ go_away = f.read(len(cls.GO_AWAY))
+ if go_away != cls.GO_AWAY:
+ raise CoverageException("Doesn't seem to be a coverage.py data file")
+ except Exception:
+ f.close()
+ raise
return f
@classmethod