[New-bugs-announce] [issue39082] AsyncMock is unable to correctly patch static or class methods

Aniket Panse report at bugs.python.org
Tue Dec 17 19:36:45 EST 2019


New submission from Aniket Panse <aniketpanse at gmail.com>:

Currently, patch is unable to correctly patch coroutinefunctions decorated with `@staticmethod` or `@classmethod`.

Example:

```
[*] aniketpanse [~/git/cpython] -> ./python                                                                                                                                                                                                         ±[master]
Python 3.9.0a1+ (heads/master:50d4f12958, Dec 17 2019, 16:31:30) 
[GCC 9.2.1 20190827 (Red Hat 9.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> class Helper:
...     @classmethod
...     async def async_class_method(cls):
...         pass
... 
>>> from unittest.mock import patch
>>> patch("Helper.async_class_method")
<unittest.mock._patch object at 0x7fc28ddbbf40>
```

This should ideally return an `AsyncMock()`.

----------
components: Tests, asyncio
messages: 358601
nosy: asvetlov, czardoz, yselivanov
priority: normal
severity: normal
status: open
title: AsyncMock is unable to correctly patch static or class methods
versions: Python 3.8, Python 3.9

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


More information about the New-bugs-announce mailing list