kuniga.me > Docs > Unit Test
Unit Test
Template
Patching
We should always patch the variables in the scope of the program we’re testing, even if itself imported them from somewhere else. Example:
my/module/program.py
:
It imported func
from lib
.
test.py
:
We patch func
from my.module.program
, not lib
.
Return Different Values
If we assign a list to side_effect
it returns the i-th value each time the function is called.
my/module/program.py
:
Mock Implementation
Assign a function to side_effect
:
Mock Throwing Exception
Assign a function to side_effect
: