kaste / mockito-python

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

How to use matchers/captor? #76

Closed programmerPhysicist closed 7 months ago

programmerPhysicist commented 8 months ago

I'm not sure how to use matchers for the requests.put() function. I tried:

# verify
postArg = captor(ANY)
verify(requests, times=1).post(postArg, postArg, postArg)

I get the following error:

>       verify(requests, times=1).post(postArg, postArg, postArg)
E       mockito.verification.VerificationError: 
E       Wanted but not invoked:
E       
E           post(<ArgumentCaptor: matcher=<function any at 0x7f5242d2ec10> values=[]>, <ArgumentCaptor: matcher=<function any at 0x7f5242d2ec10> values=[]>, <ArgumentCaptor: matcher=<function any at 0x7f5242d2ec10> values=[]>)
E       
E       Instead got:
E       
E           post(headers={'url': 'https://habitica.com', 'x-api-user': 'cd18fc9f-b649-4384-932a-f3bda6fe8102', 'x-api-key': '18f22441-2c87-6d8e-fb2a-3fa670837b5a'}, url='https://habitica.com/api/v3/tasks/user/', data={'type': 'todo', 'text': 'Test task 1', 'date': '', 'alias': '8296278113', 'priority': '2', 'attribute': 'str'})

/home/user/Workspace/Habitica-Plus-Todoist/test/integration/oneWaySync_test.py:128: VerificationError
kaste commented 8 months ago

Hi, I think that's just that you invoke post with keyword arguments but verify using positional arguments. (ANY is the default by the way so you could omit that.)

kaste commented 7 months ago

Hm, @programmerPhysicist you probably forgot about this.