mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-83076: 3.8x speed improvement in (Async)Mock instantiation (#100252)
This commit is contained in:
parent
a98d9ea56e
commit
c5726b727e
3 changed files with 36 additions and 16 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue