Closes #21270 : We now override tuple methods in mock.call objects.
diff --git a/NEWS b/NEWS
index a4fc61d..22a76fa 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,6 @@
+- Issue #21270: We now override tuple methods in mock.call objects so that
+ they can be used as normal call attributes.
+
- Issue #21256: Printout of keyword args should be in deterministic order in
a mock function call. This will help to write better doctests.
diff --git a/mock.py b/mock.py
index fa00cc4..8c0214c 100644
--- a/mock.py
+++ b/mock.py
@@ -2186,6 +2186,12 @@
return _Call(name=name, parent=self, from_kall=False)
+ def count(self, *args, **kwargs):
+ return self.__getattr__('count')(*args, **kwargs)
+
+ def index(self, *args, **kwargs):
+ return self.__getattr__('index')(*args, **kwargs)
+
def __repr__(self):
if not self.from_kall:
name = self.name or 'call'
diff --git a/tests/testmock.py b/tests/testmock.py
index f071b03..38d1699 100644
--- a/tests/testmock.py
+++ b/tests/testmock.py
@@ -1277,6 +1277,16 @@
text = "call(daddy='hero', name='hello')"
self.assertEqual(repr(m.hello.call_args), text)
+ #Issue21270 overrides tuple methods for mock.call objects
+ def test_override_tuple_methods(self):
+ c = call.count()
+ i = call.index(132,'hello')
+ m = Mock()
+ m.count()
+ m.index(132,"hello")
+ self.assertEqual(m.method_calls[0], c)
+ self.assertEqual(m.method_calls[1], i)
+
def test_mock_add_spec(self):
class _One(object):
one = 1