From 16df8f4901b3328691263573eae1f1f94874f19b Mon Sep 17 00:00:00 2001 From: John Szakmeister Date: Sat, 28 Nov 2015 05:03:09 -0500 Subject: testid: don't traceback if the idfile doesn't exist --- nose/plugins/testid.py | 55 +++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/nose/plugins/testid.py b/nose/plugins/testid.py index 0f94c87..894608d 100644 --- a/nose/plugins/testid.py +++ b/nose/plugins/testid.py @@ -176,36 +176,37 @@ class TestId(Plugin): test addresses, if they are found in my dict of tests. """ log.debug('ltfn %s %s', names, module) - fh = open(self.idfile, 'rb') try: - data = load(fh) - if 'ids' in data: - self.ids = data['ids'] - self.failed = data['failed'] - self.source_names = data['source_names'] - else: - # old ids field - self.ids = data - self.failed = [] - self.source_names = names - if self.ids: - self.id = max(self.ids) + 1 - self.tests = dict(list(zip(list(self.ids.values()), list(self.ids.keys())))) - else: - self.id = 1 - log.debug( - 'Loaded test ids %s tests %s failed %s sources %s from %s', - self.ids, self.tests, self.failed, self.source_names, - self.idfile) - 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)) + fh = open(self.idfile, 'rb') + try: + data = load(fh) + if 'ids' in data: + self.ids = data['ids'] + self.failed = data['failed'] + self.source_names = data['source_names'] + else: + # old ids field + self.ids = data + self.failed = [] + self.source_names = names + if self.ids: + self.id = max(self.ids) + 1 + self.tests = dict(list(zip(list(self.ids.values()), list(self.ids.keys())))) + else: + self.id = 1 + log.debug( + 'Loaded test ids %s tests %s failed %s sources %s from %s', + self.ids, self.tests, self.failed, self.source_names, + self.idfile) + 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)) + finally: + fh.close() except IOError: log.debug('IO error reading %s', self.idfile) - finally: - fh.close() if self.loopOnFailed and self.failed: self.collecting = False -- cgit v1.2.1