gh-91803: Mock - fix error when using autospec methods with seal (#92213)

Fixes https://github.com/python/cpython/issues/91803.

Co-authored-by: Karthikeyan Singaravelan <tir.karthi@gmail.com>
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
This commit is contained in:
andrei kulakov 2022-11-07 02:24:46 -05:00 committed by GitHub
parent 728e42fcf5
commit c6325b1c9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 1 deletions

View file

@ -200,6 +200,9 @@ class TestSealable(unittest.TestCase):
self.assertIsInstance(foo.Baz.baz, mock.NonCallableMagicMock)
self.assertIsInstance(foo.Baz.ban, mock.MagicMock)
# see gh-91803
self.assertIsInstance(foo.bar2(), mock.MagicMock)
self.assertEqual(foo.bar1(), 'a')
foo.bar1.return_value = 'new_a'
self.assertEqual(foo.bar1(), 'new_a')
@ -212,7 +215,7 @@ class TestSealable(unittest.TestCase):
with self.assertRaises(AttributeError):
foo.bar = 1
with self.assertRaises(AttributeError):
foo.bar2()
foo.bar2().x
foo.bar2.return_value = 'bar2'
self.assertEqual(foo.bar2(), 'bar2')