Pytest: Mocking slow external API call



examples/pytest/external-api/mymath.py
import externalapi

def compute(x, y):
    xx = externalapi.remote_compute(x)
    yy = externalapi.remote_compute(y)
    result = (xx+yy) ** 0.5
    return result

examples/pytest/external-api/externalapi.py
import time

def remote_compute(x):
    time.sleep(5) # to imitate long running process
    return x*x

examples/pytest/external-api/use_mymath.py
import mymath

print(mymath.compute(3, 4))