aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/unittest/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/unittest/test')
-rw-r--r--Lib/unittest/test/testmock/testmock.py8
-rw-r--r--Lib/unittest/test/testmock/testwith.py4
2 files changed, 10 insertions, 2 deletions
diff --git a/Lib/unittest/test/testmock/testmock.py b/Lib/unittest/test/testmock/testmock.py
index fdba543b535..c99098dc4ea 100644
--- a/Lib/unittest/test/testmock/testmock.py
+++ b/Lib/unittest/test/testmock/testmock.py
@@ -226,6 +226,14 @@ class MockTest(unittest.TestCase):
with self.assertRaisesRegex(InvalidSpecError,
"Cannot spec attr 'B' as the spec_set "):
mock.patch.object(A, 'B', spec_set=A.B).start()
+ with self.assertRaisesRegex(InvalidSpecError,
+ "Cannot spec attr 'B' as the spec_set "):
+ mock.patch.object(A, 'B', spec_set=A.B).start()
+ with self.assertRaisesRegex(InvalidSpecError, "Cannot spec a Mock object."):
+ mock.Mock(A.B)
+ with mock.patch('builtins.open', mock.mock_open()):
+ mock.mock_open() # should still be valid with open() mocked
+
def test_reset_mock(self):
parent = Mock()
diff --git a/Lib/unittest/test/testmock/testwith.py b/Lib/unittest/test/testmock/testwith.py
index 42ebf3898c8..c74d49a63c8 100644
--- a/Lib/unittest/test/testmock/testwith.py
+++ b/Lib/unittest/test/testmock/testwith.py
@@ -130,8 +130,8 @@ class WithTest(unittest.TestCase):
c = C()
- with patch.object(c, 'f', autospec=True) as patch1:
- with patch.object(c, 'f', autospec=True) as patch2:
+ with patch.object(c, 'f') as patch1:
+ with patch.object(c, 'f') as patch2:
c.f()
self.assertEqual(patch2.call_count, 1)
self.assertEqual(patch1.call_count, 0)