I try to use @path from unittest.mock to mock (with return value) var inside FastApi route
route is:
from . import superlogic
@router.post('/{item_id}/submit'):
async def submit(item: str):
var_i_need_to_mock = super_object.very_long_complicated_logic()
return True // nevermid
pytest:
@patch('app.router.submit'):
def test_submit(test_client):
var_i_need_to_mock = True
test_client.post('/submit') // But var_i_need_to_mock doesn't overrides
I can patch my super_object instead of var_i_need_to_mock and it works as expected like below
@patch('app.router.submit', mockobject)
What is the best practice directly override var_i_need_to_mock inside route and how to achieve this