bobber6467 / python-nose

Automatically exported from code.google.com/p/python-nose
0 stars 0 forks source link

Imported test generators are misrecognized as simple test functions #478

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
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:
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:
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:
    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.

Original issue reported on code.google.com by alessioc...@gmail.com on 5 Mar 2012 at 3:52

GoogleCodeExporter commented 8 years ago
Please report this in our new tracker on github: 
https://github.com/nose-devs/nose/issues -- development has moved there. Thanks.

Original comment by jpelle...@gmail.com on 5 Mar 2012 at 4:02