A mock should give deterministic inputs to application tests without pretending to reproduce every provider behavior. Version 0.3.1 adds OpenAI and Anthropic SDK contract coverage and hardens provider-fixture interception. The important boundary is fixture scope: installing the plugin alone does not prevent live network requests.
Use the provider fixture explicitly
python -m pip install "pytest-mockllm[openai]==0.3.1"def test_completion(mock_openai):
from openai import OpenAI
mock_openai.add_response('Ready for review')
client = OpenAI(api_key='fixture-only')
response = client.chat.completions.create(
model='gpt-4o', # Fixture model identifier; no live call
messages=[{'role': 'user', 'content': 'Report the status'}],
)
assert response.choices[0].message.content == 'Ready for review'
assert mock_openai.call_count == 1The placeholder key satisfies the SDK constructor. The active fixture intercepts the supported call. Keep real credentials out of unit-test environments and use CI egress controls if the suite must never contact a provider.
Async uses the same pytest fixture
import asyncio
def test_async_completion(mock_openai):
from openai import AsyncOpenAI
mock_openai.add_response('Async result')
async def run():
async with AsyncOpenAI(api_key='fixture-only') as client:
return await client.chat.completions.create(
model='gpt-4o',
messages=[{'role': 'user', 'content': 'Report the status'}],
)
response = asyncio.run(run())
assert response.choices[0].message.content == 'Async result'Know which interfaces are covered
OpenAI and Anthropic supported paths return official SDK response or event objects when the SDK is installed. Their active fixtures also reject unhandled base requests, including those from clients created before activation. Gemini and LangChain are not global network guards. The replacement google-genai SDK is not yet implemented by this plugin.
Token estimates are not provider invoices
Token and cost reporting is useful for comparison, but model-specific encoding, message overhead, and pricing affect the result. The old claim of greater than 99% accuracy and exact dashboard agreement has been removed. Treat totals as estimates and verify billing separately.
Recording and replay are unavailable
Recording and replay are currently unavailable. The auto, record, and replay modes fail before test code can reach a provider; they do not create or replay cassettes. Use deterministic provider fixtures instead. Redaction cannot guarantee that arbitrary data is safe to share. A successful mock test validates application behavior against the configured fixture, not the quality or safety of a live model.
Keep a separate, opt-in set of provider contract and live evaluation tests. That separation makes it clear whether a failure belongs to application logic, SDK compatibility, or actual model behavior.

