diff options
author | John Szakmeister <john@szakmeister.net> | 2014-01-08 06:22:20 -0500 |
---|---|---|
committer | John Szakmeister <john@szakmeister.net> | 2014-01-08 06:36:09 -0500 |
commit | 4e8bc02a0c591db2e3b698e50ab82038619ce260 (patch) | |
tree | 4abad8723438703da9ae6a5786c63b8fc3c2437b /nose | |
parent | fd9c694915371b9fe97facec72bb6869629b5bfb (diff) | |
download | nose-4e8bc02a0c591db2e3b698e50ab82038619ce260.tar.gz |
Fix #501: Imported test generators are treated as simple test functions
The issue is that `transplant_func()` did not preserve function
generators correctly. It would wrap the transplanted function with a
decorator, and since no yield statement was present in the decorator,
we'd lose sight of whether the transplanted function was a generator
function.
To fix this, let's check whether the function is a generator function,
and if so, use a for/yield loop to pass the results back using a
generator causing the decorator function to be seen as a generator
function. This will preserve the fact that the supplied function was a
generator function.
Diffstat (limited to 'nose')
-rw-r--r-- | nose/util.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/nose/util.py b/nose/util.py index 039163a..7995700 100644 --- a/nose/util.py +++ b/nose/util.py @@ -609,8 +609,13 @@ def transplant_func(func, module): """ from nose.tools import make_decorator - def newfunc(*arg, **kw): - return func(*arg, **kw) + if isgenerator(func): + def newfunc(*arg, **kw): + for v in func(*arg, **kw): + yield v + else: + def newfunc(*arg, **kw): + return func(*arg, **kw) newfunc = make_decorator(func)(newfunc) newfunc.__module__ = module |