Skip to content

Commit

Permalink
Fix nose-devs#777: incorrect descriptions for failed generated tests
Browse files Browse the repository at this point in the history
The final report was looking at the original function object to
determine the name, but by that time it has been modified and no longer
represents the test that failed.  This caches the description, so the
report summary can get the correct name.

wip: should we just pass in the description directly?  Seems like we
should.
  • Loading branch information
jszakmeister committed Feb 27, 2014
1 parent 014f2c5 commit 3ccc042
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions nose/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,36 @@ def runTest(self):
self.test(*self.arg)

def shortDescription(self):
# We cache the description because of the way we advocate people
# set the description for their test. The set up is typically
# something like:
#
# def test_generator():
# def func(arg):
# assert ...
# for i in range(10):
# func.description = "test_generator_%d" % i
# yield func, i
#
# This appears to work early on, but it fails when generating the report
# summary at the end of the run. To prevent it from getting
# out-of-sync, we'll go ahead and cache the description the first time
# through.
if hasattr(self, '_cached_description'):
return self._cached_description

if hasattr(self.test, 'description'):
return self.test.description
func, arg = self._descriptors()
doc = getattr(func, '__doc__', None)
if not doc:
doc = str(self)
return doc.strip().split("\n")[0].strip()
description = self.test.description
else:
func, arg = self._descriptors()
doc = getattr(func, '__doc__', None)
if not doc:
doc = str(self)
description = doc.strip().split("\n")[0].strip()

self._cached_description = description

return description


class FunctionTestCase(TestBase):
Expand Down

0 comments on commit 3ccc042

Please sign in to comment.