From 84b6fb0eea29b3b28a1a11124526b01ec0c9d17a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 6 Jan 2017 18:15:51 +0100 Subject: [PATCH] Fix unittest.mock._Call: don't ignore name Issue #28961: Fix unittest.mock._Call helper: don't ignore the name parameter anymore. Patch written by Jiajun Huang. --- Lib/unittest/mock.py | 3 +-- Lib/unittest/test/testmock/testhelpers.py | 14 ++++++++++++++ Misc/NEWS | 3 +++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index f1349198880..dcac5a29254 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -1961,9 +1961,8 @@ class _Call(tuple): If the _Call has no name then it will match any name. """ - def __new__(cls, value=(), name=None, parent=None, two=False, + def __new__(cls, value=(), name='', parent=None, two=False, from_kall=True): - name = '' args = () kwargs = {} _len = len(value) diff --git a/Lib/unittest/test/testmock/testhelpers.py b/Lib/unittest/test/testmock/testhelpers.py index 34776347daa..d5f9e7c1d69 100644 --- a/Lib/unittest/test/testmock/testhelpers.py +++ b/Lib/unittest/test/testmock/testhelpers.py @@ -306,6 +306,20 @@ class CallTest(unittest.TestCase): other_args = _Call(((1, 2), {'a': 3})) self.assertEqual(args, other_args) + def test_call_with_name(self): + self.assertEqual( + 'foo', + _Call((), 'foo')[0], + ) + self.assertEqual( + '', + _Call((('bar', 'barz'), ), )[0] + ) + self.assertEqual( + '', + _Call((('bar', 'barz'), {'hello': 'world'}), )[0] + ) + class SpecSignatureTest(unittest.TestCase): diff --git a/Misc/NEWS b/Misc/NEWS index 113ca8abbe8..456f8760526 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -42,6 +42,9 @@ Core and Builtins Library ------- +- Issue #28961: Fix unittest.mock._Call helper: don't ignore the name parameter + anymore. Patch written by Jiajun Huang. + - Issue #15812: inspect.getframeinfo() now correctly shows the first line of a context. Patch by Sam Breese.