diff options
author | Carl Meyer <carl@oddbird.net> | 2022-12-23 19:41:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-23 19:41:37 (GMT) |
commit | c5726b727e26b81a267933654cf26b760a90d9aa (patch) | |
tree | a30c81c9fd052e6e8081c28cdd787ea6d4402a7b /Lib/test/test_unittest | |
parent | a98d9ea56e7b473af54438ecc487a6bf1b4d6530 (diff) | |
download | cpython-c5726b727e26b81a267933654cf26b760a90d9aa.zip cpython-c5726b727e26b81a267933654cf26b760a90d9aa.tar.gz cpython-c5726b727e26b81a267933654cf26b760a90d9aa.tar.bz2 |
gh-83076: 3.8x speed improvement in (Async)Mock instantiation (#100252)
Diffstat (limited to 'Lib/test/test_unittest')
-rw-r--r-- | Lib/test/test_unittest/testmock/testasync.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_unittest/testmock/testasync.py b/Lib/test/test_unittest/testmock/testasync.py index e05a228..52a3b71 100644 --- a/Lib/test/test_unittest/testmock/testasync.py +++ b/Lib/test/test_unittest/testmock/testasync.py @@ -300,6 +300,19 @@ class AsyncSpecTest(unittest.TestCase): self.assertIsInstance(mock.async_method, AsyncMock) self.assertIsInstance(mock.normal_method, Mock) + def test_spec_async_attributes_instance(self): + async_instance = AsyncClass() + async_instance.async_func_attr = async_func + async_instance.later_async_func_attr = normal_func + + mock_async_instance = Mock(spec_set=async_instance) + + async_instance.later_async_func_attr = async_func + + self.assertIsInstance(mock_async_instance.async_func_attr, AsyncMock) + # only the shape of the spec at the time of mock construction matters + self.assertNotIsInstance(mock_async_instance.later_async_func_attr, AsyncMock) + def test_spec_mock_type_kw(self): def inner_test(mock_type): async_mock = mock_type(spec=async_func) |