This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: mock.patch decorating a generator returns a regular function.
Type: behavior Stage: test needed
Components: Tests Versions: Python 3.6, Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: michael.foord, rbcollins, shoshber, terry.reedy, xtreak
Priority: normal Keywords:

Created on 2016-06-17 05:35 by shoshber, last changed 2022-04-11 14:58 by admin.

Files
File name Uploaded Description Edit
silentfail.py shoshber, 2016-06-18 04:37 example tests
actual.out shoshber, 2016-06-18 04:37 output
Messages (6)
msg268709 - (view) Author: Shoshana Berleant (shoshber) Date: 2016-06-17 05:35
(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: https://github.com/testing-cabal/mock/issues/366
msg268749 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-06-18 00:07
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.
msg268757 - (view) Author: Robert Collins (rbcollins) * (Python committer) Date: 2016-06-18 03:58
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.
msg268758 - (view) Author: Robert Collins (rbcollins) * (Python committer) Date: 2016-06-18 03:59
Once fixed in CPython, we'll put the backport in mock, for folk using older Python's.
msg268761 - (view) Author: Shoshana Berleant (shoshber) Date: 2016-06-18 04:37
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.
msg268762 - (view) Author: Shoshana Berleant (shoshber) Date: 2016-06-18 04:37
output
History
Date User Action Args
2022-04-11 14:58:32adminsetgithub: 71528
2019-12-13 11:13:51xtreaksetnosy: + xtreak
2016-06-18 04:37:56shoshbersetfiles: + actual.out

messages: + msg268762
2016-06-18 04:37:27shoshbersetfiles: + silentfail.py

messages: + msg268761
2016-06-18 03:59:32rbcollinssetmessages: + msg268758
versions: - Python 2.7, Python 3.2, Python 3.3, Python 3.4
2016-06-18 03:58:59rbcollinssetnosy: + rbcollins

messages: + msg268757
title: mock.patch decorator fails silently on generators -> mock.patch decorating a generator returns a regular function.
2016-06-18 00:07:11terry.reedysetnosy: + terry.reedy, michael.foord

messages: + msg268749
stage: test needed
2016-06-17 05:35:08shoshbercreate