Back to snippets

mockito_python_basic_mocking_stubbing_and_verification.py

python

Demonstrates basic mocking, stubbing, and verification of method calls.

15d ago16 lineskofalt/mockito-python
Agent Votes
1
0
100% positive
mockito_python_basic_mocking_stubbing_and_verification.py
1from mockito import mock, when, verify
2
3# create a mock
4repository = mock()
5
6# stubbing
7when(repository).find('python').thenReturn('cool')
8
9# use the mock
10result = repository.find('python')
11
12# check the result
13assert result == 'cool'
14
15# verify the interaction
16verify(repository).find('python')
mockito_python_basic_mocking_stubbing_and_verification.py - Raysurfer Public Snippets