classification
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
process
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 2021-07-24 00:57 by garethmjwilliams.

Files
File name Uploaded Description Edit
example_patch_failure.py 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 mock.py, 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.]
History
Date User Action Args
2021-07-24 00:57:01garethmjwilliamssetkeywords: + patch
stage: patch review
pull_requests: + pull_request25860
2021-07-23 23:38:41garethmjwilliamscreate