Skip to content

Commit

Permalink
Close idfile object in a finally clause
Browse files Browse the repository at this point in the history
  • Loading branch information
Renzo Lucioni authored and jszakmeister committed Nov 28, 2015
1 parent ad63d9a commit 53ca70f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions nose/plugins/testid.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ def loadTestsFromNames(self, names, module=None):
test addresses, if they are found in my dict of tests.
"""
log.debug('ltfn %s %s', names, module)
fh = open(self.idfile, 'rb')
try:
fh = open(self.idfile, 'rb')
data = load(fh)
if 'ids' in data:
self.ids = data['ids']
Expand All @@ -197,14 +197,15 @@ def loadTestsFromNames(self, names, module=None):
'Loaded test ids %s tests %s failed %s sources %s from %s',
self.ids, self.tests, self.failed, self.source_names,
self.idfile)
fh.close()
except ValueError, e:
# load() may throw a ValueError when reading the ids file, if it
# was generated with a newer version of Python than we are currently
# running.
log.debug('Error loading %s : %s', self.idfile, str(e))
except IOError:
log.debug('IO error reading %s', self.idfile)
finally:
fh.close()

if self.loopOnFailed and self.failed:
self.collecting = False
Expand Down

0 comments on commit 53ca70f

Please # to comment.