kaste / mockito-python

Mockito is a spying framework
MIT License
123 stars 12 forks source link

captor is capturing even when the whole signature doesn't match. #49

Closed avandierast closed 2 years ago

avandierast commented 2 years ago

Hello again :)

I've detected a bug with captor. It is called in the argument matching phase but if the matching phase fails, the argument is still remembered in the captor. It is visible when using captors with two different signatures of the same function:

from mockito import when, captor, ANY

class A:
    @staticmethod
    def method(a,b):
        pass

a = captor()
when(A).method(a, ANY(int)).thenReturn()
when(A).method(a, ANY(str)).thenReturn()

A.method(10, 20)

print(a.all_values)
# [10, 10]
kaste commented 2 years ago

Sure that's a bug. Looks like Matcher.matches already has the side-effect of remembering its usage. That is conceptually wrong because verify(A).method(a, ...) would also count as usage.

avandierast commented 2 years ago

Thanks for the quick bugfix :)