Async is supported out of the box and you don't have to do anything different from defining synchronous tests. The only additional bit of setup needed is you need to also install the pytest-asyncio plugin and mark the test as async.
importpytestimportopenaiimportopenai_responsesfromopenai_responsesimportOpenAIMock@pytest.mark.asyncio@openai_responses.mock()asyncdeftest_async_create_chat_completion(openai_mock:OpenAIMock):openai_mock.chat.completions.create.response={"choices":[{"index":0,"finish_reason":"stop","message":{"content":"Hello! How can I help?","role":"assistant"},}]}client=openai.AsyncClient(api_key="sk-fake123")completion=awaitclient.chat.completions.create(model="gpt-3.5-turbo",messages=[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"Hello!"},],)assertlen(completion.choices)==1assertcompletion.choices[0].message.content=="Hello! How can I help?"assertopenai_mock.chat.completions.create.calls.call_count==1
importopenaiimportopenai_responsesfromopenai_responsesimportOpenAIMock@openai_responses.mock()deftest_create_chat_completion(openai_mock:OpenAIMock):openai_mock.chat.completions.create.response={"choices":[{"index":0,"finish_reason":"stop","message":{"content":"Hello! How can I help?","role":"assistant"},}]}client=openai.Client(api_key="sk-fake123")completion=client.chat.completions.create(model="gpt-3.5-turbo",messages=[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"Hello!"},],)assertlen(completion.choices)==1assertcompletion.choices[0].message.content=="Hello! How can I help?"assertopenai_mock.chat.completions.create.calls.call_count==1