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.

Title: unittest.mock.patch does not work as a decorator on generator functions
Type: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.8
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: garethmjwilliams
Priority: normal Keywords: patch

Created on 2021-07-23 23:38 by garethmjwilliams, last changed 2022-04-11 14:59 by admin.

File name Uploaded Description Edit garethmjwilliams, 2021-07-23 23:38 Example of failure on simple patch of `len`
Pull Requests
URL Status Linked Edit
PR 27315 open garethmjwilliams, 2021-07-24 00:57
Messages (1)
msg398104 - (view) Author: Gareth Williams (garethmjwilliams) * Date: 2021-07-23 23:38
unitest.mock.patch does not work well when applied as a decorator to a function which is a generator.

It results in the function being changed from a generator function (co_flags 99) to a non-generator (co_flag 31) and the patch is not applied.

[I have a MWE, attached, and fairly simple fix, to the file, which I will put up as a PR in due course. This is the first time I've submitted a bug or PR, so apologies if I've not done this particularly well.]
Date User Action Args
2022-04-11 14:59:47adminsetgithub: 88893
2021-07-24 00:57:01garethmjwilliamssetkeywords: + patch
stage: patch review
pull_requests: + pull_request25860
2021-07-23 23:38:41garethmjwilliamscreate