nose-devs/nose — Issue #501: Imported test generators are misrecognized as simple test functions
Author: alefend
Created: 2012-03-05 16:16:25+00:00
State: open

I have a factory function which returns a test generator. I want to use this function in different test modules in order to get a similar set of test generators with the ability to change some parameters:

Module **util.py**:

```python
def FooTestFactory(p1, p2):
def check(a):
assert a == p1
assert a == p2

def test_func():
for a in [1, 2, 3]:
yield check, a
return test_func
```

Module **test.py**:

```python
from util import FooTestFactory
test_foo = FooTestFactory(1, 2)
```

When running nosetests I would expect to have the full set of generated tests to be executed, instead I only got the execution of test_func as it would be a simple test function:
```
test.test_func ... ok
```

This misbehaviour seems to be caused by _makeTest from loader.py, at line 555:

```python
elif isfunction(obj):
if parent and obj.__module__ != parent.__name__:
obj = transplant_func(obj, parent.__name__)
if isgenerator(obj):
return self.loadTestsFromGenerator(obj, parent)
else:
return FunctionTestCase(obj)
```

Since the function is imported from another module it will be transplanted (which decorates the original function) but then, because of the decoration, the following isgenerator() check will fail.