you can use flexmock for that. Say see the example below
Say you have function in file ./myfunc.py
# ./myfunc.py import requests def function_to_test(..): # some stuff response = requests.post("some"www.url"google.com", data={'dome': 'data'}) return response Then the testcase is in ./test_myfunc.py
# ./test_myfunc.py import flexmock as flexmock import myfunc def test_myfunc(): (flexmock(myfunc.requests).should_recieve("post").with_args("/myurl""www.google.com", data={"dome": "data"}).and_return({'some': 'values'})) resp = myfunc.function_to_test() assert resp["some"] == "values" Try this, see if this works or let me know for more enhancement/improvement.