diff options
author | Matthew Suozzo <msuozzo@google.com> | 2022-02-03 03:41:19 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-03 00:41:19 -0800 |
commit | 6394e981adaca2c0daa36c8701611e250d74024c (patch) | |
tree | e045af3b3a17ab2bfa72e44aa711ad046c8ba4bb /Lib/unittest/test/testmock/testmock.py | |
parent | 8726067ace98a27557e9fdf1a8e1c509c37cfcfc (diff) | |
download | cpython-6394e981adaca2c0daa36c8701611e250d74024c.tar.gz cpython-6394e981adaca2c0daa36c8701611e250d74024c.zip |
Restrict use of Mock objects as specs (GH-31090)
Follow-on to https://github.com/python/cpython/pull/25326
This covers cases where mock objects are passed directly to spec.
Diffstat (limited to 'Lib/unittest/test/testmock/testmock.py')
-rw-r--r-- | Lib/unittest/test/testmock/testmock.py | 8 |
1 files changed, 8 insertions, 0 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() |