Introduction¶
๐งช๐ค Pytest plugin for automatically mocking OpenAI requests. Powered by RESPX.
Why mock?¶
Mocking is a common practice in software testing. Instead of sending requests over the network, you can patch the requests to return predefined responses.
This has many benefits:
- ๐ค Cost: Don't pay for actual API usage
- ๐๏ธ Speed: Completely avoid the network
- ๐ Security: Nothing actually leaves the machine
- ๐ฎ Control: 100% certainty on what will be received
Installation¶
Available on PyPi
First steps¶
Before getting started, make sure that you've installed pytest. For async support, you can see more setup instructions here.
Quickstart¶
Simply decorate any test function that makes a call to the OpenAI API.
See examples for more.
Note
The API call(s) can either come from the official Python library, HTTPX, or HTTP Core. All documented examples will use the official Python library.
- Decorate the test function
- Use the test fixture
- Define the response
- Call the API the way you normally would (including async support)
- Optionally use the call history to add additional assertions