Repository: kaste/mockito-python

Issue:
TypeError: return_() got multiple values for argument 'value' 
Seeing an error arising when using `value` as a keyword argument to a mockito `when`.

In `producer.py`:

```
def send(value):
    return value
```

In `mocking_check.py`:

```
from mockito import when

import producer

when(producer).send(value="test").thenReturn("Nope")

print(producer.send(value="test")
```

When running this the output is: `TypeError: return_() got multiple values for argument 'value' `

Result expected: `Nope`

Anyone know why this is the case. Attempting to mock a method with a similar signature - it worked but failed as soon as the `value` kwarg was introduced.


Discussion:

Patch:
diff --git a/mockito/invocation.py b/mockito/invocation.py
index 46f4844..01bf682 100644
--- a/mockito/invocation.py
+++ b/mockito/invocation.py
@@ -18,7 +18,6 @@
 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 # THE SOFTWARE.
 
-import functools
 import inspect
 import operator
 from collections import deque
@@ -407,10 +406,14 @@ class StubbedInvocation(MatchingInvocation):
 
 
 def return_(value, *a, **kw):
-    return value
+    def answer(*a, **kw):
+        return value
+    return answer
 
 def raise_(exception, *a, **kw):
-    raise exception
+    def answer(*a, **kw):
+        raise exception
+    return answer
 
 
 def discard_self(function):
@@ -429,13 +432,13 @@ class AnswerSelector(object):
 
     def thenReturn(self, *return_values):
         for return_value in return_values:
-            answer = functools.partial(return_, return_value)
+            answer = return_(return_value)
             self.__then(answer)
         return self
 
     def thenRaise(self, *exceptions):
         for exception in exceptions:
-            answer = functools.partial(raise_, exception)
+            answer = raise_(exception)
             self.__then(answer)
         return self
 


Test patch:
diff --git a/tests/issue_82_test.py b/tests/issue_82_test.py
new file mode 100644
index 0000000..54ee678
--- /dev/null
+++ b/tests/issue_82_test.py
@@ -0,0 +1,12 @@
+import pytest
+from mockito import when
+
+from . import module
+
+
+@pytest.mark.usefixtures('unstub')
+class TestIssue82:
+    def testFunctionWithArgumentNamedValue(self):
+        when(module).send(value="test").thenReturn("nope")
+        assert module.send(value="test") == "nope"
+
diff --git a/tests/module.py b/tests/module.py
index 1d11c56..a69daad 100644
--- a/tests/module.py
+++ b/tests/module.py
@@ -6,3 +6,7 @@ class Foo(object):
 
 def one_arg(arg):
     return arg
+
+
+def send(value):
+    return value