summaryrefslogtreecommitdiff
path: root/Lib/unittest/test/testmock/testasync.py
diff options
context:
space:
mode:
authorShantanu <12621235+hauntsaninja@users.noreply.github.com>2022-12-24 14:39:27 -0600
committerGitHub <noreply@github.com>2022-12-24 14:39:27 -0600
commit9975d4e7bac052c320880e026f757cddaa91b4bf (patch)
tree23ab1fb87e575d8f5eff6a0b65846fbe86055384 /Lib/unittest/test/testmock/testasync.py
parentad8d2ef54ffde39c6d59c4fc6c0e9b8c529b306d (diff)
downloadcpython-git-9975d4e7bac052c320880e026f757cddaa91b4bf.tar.gz
[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/test/testmock/testasync.py')
-rw-r--r--Lib/unittest/test/testmock/testasync.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/Lib/unittest/test/testmock/testasync.py b/Lib/unittest/test/testmock/testasync.py
index 22228b47de..61269d637f 100644
--- a/Lib/unittest/test/testmock/testasync.py
+++ b/Lib/unittest/test/testmock/testasync.py
@@ -8,7 +8,7 @@ from contextlib import contextmanager
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():
@@ -298,6 +298,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_mock_type_kw(self):
def inner_test(mock_type):
async_mock = mock_type(spec=async_func)
@@ -1074,3 +1082,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()