pytest fixtures for aimock — mock LLM APIs, MCP, A2A, vector DBs
Project description
aimock-pytest
pytest fixtures for aimock — mock LLM APIs, MCP tools, A2A agents, vector databases, and more.
Install
# From PyPI (once published):
pip install aimock-pytest
# Local install from a repo checkout:
pip install ./packages/aimock-pytest
Requires: Node.js >= 20 on PATH (or set AIMOCK_NODE_PATH).
Quick Start
The plugin auto-registers two fixtures: aimock (function-scoped) and aimock_session (session-scoped).
def test_hello(aimock):
import requests
# Set up a fixture
aimock.on_message("hello", {"content": "Hi there!"})
# Point your SDK at aimock
r = requests.post(
f"{aimock.base_url}/v1/chat/completions",
json={
"model": "gpt-4",
"messages": [{"role": "user", "content": "hello"}],
},
)
assert r.json()["choices"][0]["message"]["content"] == "Hi there!"
Fixtures
| Fixture | Scope | Description |
|---|---|---|
aimock |
function | Fresh server per test |
aimock_session |
session | Shared server across all tests |
Server API
# Add fixtures
aimock.on_message("pattern", {"content": "response"})
aimock.on_embedding("pattern", {"embedding": [0.1, 0.2]})
aimock.add_fixture(match={...}, response={...}, chunkSize=10, latency=50)
aimock.load_fixtures("path/to/fixtures.json")
# Inspect
aimock.get_journal() # list of all recorded requests
aimock.get_last_request() # most recent request or None
# Error injection
aimock.next_error(429, {"message": "Rate limited"})
# Reset
aimock.clear_fixtures() # remove all fixtures
aimock.reset() # clear fixtures + journal
CLI Options
--aimock-node PATH Path to node binary
--aimock-version VER aimock npm version (default: 1.7.0)
Environment Variables
| Variable | Description |
|---|---|
AIMOCK_NODE_PATH |
Path to node binary |
AIMOCK_CACHE_DIR |
Override cache directory (default: ~/.cache/aimock) |
Development
Prerequisites
- Node.js >= 20
- Python >= 3.10
- pnpm
Running tests locally
Build the npm package first, then point AIMOCK_CLI_PATH at the local build:
pnpm install && pnpm run build
AIMOCK_CLI_PATH=../../dist/cli.js pytest tests/ -v
If you install the test dependencies and run from the packages/aimock-pytest/
directory, conftest.py will auto-detect the local build so you can omit the
env var:
pip install ./packages/aimock-pytest[test]
cd packages/aimock-pytest
pytest tests/ -v
How CI works
The test-pytest.yml workflow:
- Checks out the repo
- Builds the TypeScript package (
pnpm run build) - Sets
AIMOCK_CLI_PATHto the localdist/cli.js - Installs
aimock-pytest[test]and runspytest
Tests run across a matrix of Python 3.10--3.13 and Node 20/22.
The publish-pytest.yml workflow publishes to PyPI on pushes to main when
the version in pyproject.toml has not already been published.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aimock_pytest-0.2.0.tar.gz.
File metadata
- Download URL: aimock_pytest-0.2.0.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b7bba1ee7afe798113c119185c0794229cfdebb8a27b83bc3f361fd6a6895a6
|
|
| MD5 |
ad2fe288c7de2de6297d98b7c6005f11
|
|
| BLAKE2b-256 |
1846f8e483f2bdcb62f07426f130e89a52cbc8aef179c638a7c3ba3ddf35f44e
|
Provenance
The following attestation bundles were made for aimock_pytest-0.2.0.tar.gz:
Publisher:
publish-pytest.yml on CopilotKit/aimock
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aimock_pytest-0.2.0.tar.gz -
Subject digest:
2b7bba1ee7afe798113c119185c0794229cfdebb8a27b83bc3f361fd6a6895a6 - Sigstore transparency entry: 1244012124
- Sigstore integration time:
-
Permalink:
CopilotKit/aimock@ac602105e8582d720e4847a909a68ad8d96cb4e8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/CopilotKit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pytest.yml@ac602105e8582d720e4847a909a68ad8d96cb4e8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file aimock_pytest-0.2.0-py3-none-any.whl.
File metadata
- Download URL: aimock_pytest-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e08fed630402654e71067dc3ad17773f6fdb6a69897d5d822f077dec2d91ffc
|
|
| MD5 |
9eef106052c79a866f98251197467999
|
|
| BLAKE2b-256 |
d08565addaf5267eb363cb0ffa2b395018738354cf92438e438e7581f43990c2
|
Provenance
The following attestation bundles were made for aimock_pytest-0.2.0-py3-none-any.whl:
Publisher:
publish-pytest.yml on CopilotKit/aimock
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aimock_pytest-0.2.0-py3-none-any.whl -
Subject digest:
9e08fed630402654e71067dc3ad17773f6fdb6a69897d5d822f077dec2d91ffc - Sigstore transparency entry: 1244012263
- Sigstore integration time:
-
Permalink:
CopilotKit/aimock@ac602105e8582d720e4847a909a68ad8d96cb4e8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/CopilotKit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pytest.yml@ac602105e8582d720e4847a909a68ad8d96cb4e8 -
Trigger Event:
push
-
Statement type: