mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
[3.11] gh-100287: Fix unittest.mock.seal with AsyncMock (GH-100496) (#100506)
(cherry picked from commit e4b43ebb3a
)
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
This commit is contained in:
parent
44b664e057
commit
75b75dfdac
3 changed files with 18 additions and 5 deletions
|
@ -1014,15 +1014,15 @@ class NonCallableMock(Base):
|
|||
|
||||
For non-callable mocks the callable variant will be used (rather than
|
||||
any custom subclass)."""
|
||||
_new_name = kw.get("_new_name")
|
||||
if _new_name in self.__dict__['_spec_asyncs']:
|
||||
return AsyncMock(**kw)
|
||||
|
||||
if self._mock_sealed:
|
||||
attribute = f".{kw['name']}" if "name" in kw else "()"
|
||||
mock_name = self._extract_mock_name() + attribute
|
||||
raise AttributeError(mock_name)
|
||||
|
||||
_new_name = kw.get("_new_name")
|
||||
if _new_name in self.__dict__['_spec_asyncs']:
|
||||
return AsyncMock(**kw)
|
||||
|
||||
_type = type(self)
|
||||
if issubclass(_type, MagicMock) and _new_name in _async_method_magics:
|
||||
# Any asynchronous magic becomes an AsyncMock
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue