diff options
author | Shantanu <12621235+hauntsaninja@users.noreply.github.com> | 2022-12-24 20:39:27 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-24 20:39:27 (GMT) |
commit | 9975d4e7bac052c320880e026f757cddaa91b4bf (patch) | |
tree | 23ab1fb87e575d8f5eff6a0b65846fbe86055384 /Lib/unittest/mock.py | |
parent | ad8d2ef54ffde39c6d59c4fc6c0e9b8c529b306d (diff) | |
download | cpython-9975d4e7bac052c320880e026f757cddaa91b4bf.zip cpython-9975d4e7bac052c320880e026f757cddaa91b4bf.tar.gz cpython-9975d4e7bac052c320880e026f757cddaa91b4bf.tar.bz2 |
[3.10] gh-100287: Fix unittest.mock.seal with AsyncMock (GH-100496) (#100508)
(cherry picked from commit e4b43ebb3afbd231a4e5630e7e358aa3093f8677)
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Diffstat (limited to 'Lib/unittest/mock.py')
-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 a647e5d..7832092 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -1010,15 +1010,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 |