Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c667b09

Browse files
tirkarthicjw296
authored andcommitted
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
1 parent 68b56d0 commit c667b09

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

Lib/unittest/test/testmock/testhelpers.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
)
99

1010
from datetime import datetime
11+
from functools import partial
1112

1213
class SomeClass(object):
1314
def one(self, a, b):
@@ -871,6 +872,19 @@ def test_autospec_on_bound_builtin_function(self):
871872
mocked.assert_called_once_with(4, 5, 6)
872873

873874

875+
def test_autospec_getattr_partial_function(self):
876+
# bpo-32153 : getattr returning partial functions without
877+
# __name__ should not create AttributeError in create_autospec
878+
class Foo:
879+
880+
def __getattr__(self, attribute):
881+
return partial(lambda name: name, attribute)
882+
883+
proxy = Foo()
884+
autospec = create_autospec(proxy)
885+
self.assertFalse(hasattr(autospec, '__name__'))
886+
887+
874888
class TestCallList(unittest.TestCase):
875889

876890
def test_args_list_contains_call_list(self):

0 commit comments

Comments
 (0)