[Python-checkins] bpo-32153: Add unit test for create_autospec with partial function returned in getattr (#10398)

Chris Withers webhook-mailer at python.org
Mon Dec 3 02:58:26 EST 2018


https://github.com/python/cpython/commit/c667b094ae37799a7e42ba5cd2ad501cc7920888
commit: c667b094ae37799a7e42ba5cd2ad501cc7920888
branch: master
author: Xtreak <tirkarthi at users.noreply.github.com>
committer: Chris Withers <chris at simplistix.co.uk>
date: 2018-12-03T07:58:15Z
summary:

bpo-32153: Add unit test for create_autospec with partial function returned in getattr (#10398)

* Add create_autospec with partial function returned in getattr

* Use self.assertFalse instead of assert

* Use different names and remove object

files:
M Lib/unittest/test/testmock/testhelpers.py

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 datetime import datetime
+from functools import partial
 
 class SomeClass(object):
     def one(self, a, b):
@@ -871,6 +872,19 @@ def test_autospec_on_bound_builtin_function(self):
         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):



More information about the Python-checkins mailing list