From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Mon, 3 Dec 2018 08:26:06 +0000 (-0800) Subject: bpo-32153: Add unit test for create_autospec with partial function returned in getatt... X-Git-Tag: v3.7.2rc1~68 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1ef06c62d3c05cbba6448c56af30a09c551c9ec2;p=thirdparty%2FPython%2Fcpython.git bpo-32153: Add unit test for create_autospec with partial function returned in getattr (GH-10398) (#10855) * Add create_autospec with partial function returned in getattr * Use self.assertFalse instead of assert * Use different names and remove object (cherry picked from commit c667b094ae37799a7e42ba5cd2ad501cc7920888) Co-authored-by: Xtreak --- diff --git a/Lib/unittest/test/testmock/testhelpers.py b/Lib/unittest/test/testmock/testhelpers.py index 7919482ae99c..9edebf551660 100644 --- a/Lib/unittest/test/testmock/testhelpers.py +++ b/Lib/unittest/test/testmock/testhelpers.py @@ -8,6 +8,7 @@ from unittest.mock import ( ) from datetime import datetime +from functools import partial class SomeClass(object): def one(self, a, b): @@ -871,6 +872,19 @@ class SpecSignatureTest(unittest.TestCase): mocked.assert_called_once_with(4, 5, 6) + def test_autospec_getattr_partial_function(self): + # bpo-32153 : getattr returning partial functions without + # __name__ should not create AttributeError in create_autospec + class Foo: + + def __getattr__(self, attribute): + return partial(lambda name: name, attribute) + + proxy = Foo() + autospec = create_autospec(proxy) + self.assertFalse(hasattr(autospec, '__name__')) + + class TestCallList(unittest.TestCase): def test_args_list_contains_call_list(self):