[New-bugs-announce] [issue44730] unittest.mock.patch does not work as a decorator on generator functions

Gareth Williams report at bugs.python.org
Fri Jul 23 19:38:41 EDT 2021


New submission from Gareth Williams <gareth.m.j.williams at gmail.com>:

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.]

----------
components: Library (Lib)
files: example_patch_failure.py
messages: 398104
nosy: garethmjwilliams
priority: normal
severity: normal
status: open
title: unittest.mock.patch does not work as a decorator on generator functions
type: enhancement
versions: Python 3.8
Added file: https://bugs.python.org/file50176/example_patch_failure.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44730>
_______________________________________


More information about the New-bugs-announce mailing list