I realized this afternoon, while writing some more tests, that tests with the patch decorator were all reported as "OK", even when I wanted them to fail. Turns out they aren't being run at all.
I commented out all the yield statements, and the tests ran just as they should.
I don't know exactly what is going on here, but might raising an error or warning be good here?
Firstly, the generator's body will run without the patch (because the wrapping function has
try:
return decorated(..)
finally:
unpwatch()
Secondly, the wrapping function is itself not a generator, and anything that introspects functions to see if they are generators will not detect the wrapped function as one - which is I suspect whats tripping nose up, but I haven't actually checked the nose code to see what its doing/expecting.
changed the title [-]mock.patch decorator fails silently on generators[/-][+]mock.patch decorating a generator returns a regular function.[/+]on Jun 18, 2016
Activity
shoshber commented on Jun 17, 2016
(at least in my case)
I committed two tests before I realized the tests were not being run: https://github.com/nipy/nipype/blob/abe7920a051f1570ccce4b71f26f50102d6e4e12/nipype/testing/tests/test_utils.py#L23
I realized this afternoon, while writing some more tests, that tests with the patch decorator were all reported as "OK", even when I wanted them to fail. Turns out they aren't being run at all.
I commented out all the yield statements, and the tests ran just as they should.
I don't know exactly what is going on here, but might raising an error or warning be good here?
Originally filed here: testing-cabal/mock#366
terryjreedy commented on Jun 18, 2016
3.2 to 3.4 only get security fixes
please provide a simple test that fails now and that you think should pass or at least warn.
rbtcollins commented on Jun 18, 2016
There are two related things here.
Firstly, the generator's body will run without the patch (because the wrapping function has
try:
return decorated(..)
finally:
unpwatch()
Secondly, the wrapping function is itself not a generator, and anything that introspects functions to see if they are generators will not detect the wrapped function as one - which is I suspect whats tripping nose up, but I haven't actually checked the nose code to see what its doing/expecting.
rbtcollins commented on Jun 18, 2016
Once fixed in CPython, we'll put the backport in mock, for folk using older Python's.
shoshber commented on Jun 18, 2016
I attached a file with 4 tests and the output. nosetests reports that all four tests were executed. In reality, only two tests were executed.
shoshber commented on Jun 18, 2016
output