gh-83076: 3.8x speed improvement in (Async)Mock instantiation (#100252)

This commit is contained in:
Carl Meyer 2022-12-23 12:41:37 -07:00 committed by GitHub
parent a98d9ea56e
commit c5726b727e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 16 deletions

View file

@ -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)