diff options
author | Shantanu <12621235+hauntsaninja@users.noreply.github.com> | 2022-12-24 19:39:39 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-24 19:39:39 (GMT) |
commit | e4b43ebb3afbd231a4e5630e7e358aa3093f8677 (patch) | |
tree | 03fa3d002c6d84b0f54bf5be9251df7e455b7ba7 /Lib/unittest | |
parent | 46e6a28308def2c3a71c679a6fa4ed7d520802b9 (diff) | |
download | cpython-e4b43ebb3afbd231a4e5630e7e358aa3093f8677.zip cpython-e4b43ebb3afbd231a4e5630e7e358aa3093f8677.tar.gz cpython-e4b43ebb3afbd231a4e5630e7e358aa3093f8677.tar.bz2 |
gh-100287: Fix unittest.mock.seal with AsyncMock (#100496)
Diffstat (limited to 'Lib/unittest')
-rw-r--r-- | Lib/unittest/mock.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index 583ab74..994947c 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -1019,15 +1019,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 |