Testing an API that uses PrefectClient

I have an API that communicates with Prefect as follows:

    async with prefect.get_client() as client:
        deployment = await client.read_deployment_by_name("my-deployment")
        flow_run = await client.create_flow_run_from_deployment(deployment.id)

I was planning to mock the requests that the client makes with requests_mock. I thought those requests would be to


When I try to test this, the mocks aren’t called. I have set os.environ["PREFECT_API_URL"] = "http://localhost:4200/api", but my client.api_url is http://ephemeral-prefect/api/. Using that as the PREFECT_API_URL doesn’t help either.

The source for get_client() shows it gets its API URL from

from prefect.settings import PREFECT_API_URL

api = PREFECT_API_URL.value()  # This returns None

How can I get an API url into the client settings, or how else should I mock the PrefectClient?

I am on Prefect 2.10.4.

I guess I ended up just mocking that the client was called, with