]> granicus.if.org Git - python/commitdiff
bpo-32153: Add unit test for create_autospec with partial function returned in getatt...
authorXtreak <tirkarthi@users.noreply.github.com>
Mon, 3 Dec 2018 07:58:15 +0000 (13:28 +0530)
committerChris Withers <chris@simplistix.co.uk>
Mon, 3 Dec 2018 07:58:15 +0000 (07:58 +0000)
* Add create_autospec with partial function returned in getattr

* Use self.assertFalse instead of assert

* Use different names and remove object

Lib/unittest/test/testmock/testhelpers.py

index 7919482ae99c7f07e2726edd9418620e99c2427c..9edebf5516600971e8aca02cac336531ed706e82 100644 (file)
@@ -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):