I am trying to do exception unit test for check_name()
function but create_list()
is also called. Is there any way I can mock the output of create_list()
instead of executing it?
def create_list(token):
return service_list
def check_name(token, name):
response = create_list(token)
existed_list = [app.name for app in response.details]
if name in existed_list:
raise NameExists()
I tried this but it still called create_list()
def test_exception_existed_name(self):
existed_list = [ "p", "r", "g", "x"]
with pytest.raises(NameExists):
check_name(token, "g")
check_name()
and create_list()
in sp.py
project
│
└───src
│ └───sp_api
│ └───api
│ sp.py
│
└───tests
test_sp.py