summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
authorXtreak <tirkarthi@users.noreply.github.com>2018-12-03 07:58:15 (GMT)
committerChris Withers <chris@simplistix.co.uk>2018-12-03 07:58:15 (GMT)
commitc667b094ae37799a7e42ba5cd2ad501cc7920888 (patch)
tree7036837b0d32d8f9c58b0c1feb8954781d665cc4 /Lib/unittest
parent68b56d02ef20479b87c65e523cf3dec1b7b77d40 (diff)
downloadcpython-c667b094ae37799a7e42ba5cd2ad501cc7920888.zip
cpython-c667b094ae37799a7e42ba5cd2ad501cc7920888.tar.gz
cpython-c667b094ae37799a7e42ba5cd2ad501cc7920888.tar.bz2
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
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/test/testmock/testhelpers.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/unittest/test/testmock/testhelpers.py b/Lib/unittest/test/testmock/testhelpers.py
index 7919482..9edebf5 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):