mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-100287: Fix unittest.mock.seal with AsyncMock (#100496)
This commit is contained in:
parent
46e6a28308
commit
e4b43ebb3a
3 changed files with 18 additions and 5 deletions
|
@ -11,7 +11,7 @@ support.requires_working_socket(module=True)
|
|||
from asyncio import run, iscoroutinefunction
|
||||
from unittest import IsolatedAsyncioTestCase
|
||||
from unittest.mock import (ANY, call, AsyncMock, patch, MagicMock, Mock,
|
||||
create_autospec, sentinel, _CallList)
|
||||
create_autospec, sentinel, _CallList, seal)
|
||||
|
||||
|
||||
def tearDownModule():
|
||||
|
@ -300,6 +300,14 @@ class AsyncSpecTest(unittest.TestCase):
|
|||
self.assertIsInstance(mock.async_method, AsyncMock)
|
||||
self.assertIsInstance(mock.normal_method, Mock)
|
||||
|
||||
def test_spec_normal_methods_on_class_with_mock_seal(self):
|
||||
mock = Mock(AsyncClass)
|
||||
seal(mock)
|
||||
with self.assertRaises(AttributeError):
|
||||
mock.normal_method
|
||||
with self.assertRaises(AttributeError):
|
||||
mock.async_method
|
||||
|
||||
def test_spec_async_attributes_instance(self):
|
||||
async_instance = AsyncClass()
|
||||
async_instance.async_func_attr = async_func
|
||||
|
@ -1089,3 +1097,7 @@ class AsyncMockAssert(unittest.TestCase):
|
|||
'Actual: [call(1)]'))) as cm:
|
||||
self.mock.assert_has_awaits([call(), call(1, 2)])
|
||||
self.assertIsInstance(cm.exception.__cause__, TypeError)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue