Skip to main content

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:

  1. Checks out the repo
  2. Builds the TypeScript package (pnpm run build)
  3. Sets AIMOCK_CLI_PATH to the local dist/cli.js
  4. Installs aimock-pytest[test] and runs pytest

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aimock_pytest-0.2.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aimock_pytest-0.2.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

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

Hashes for aimock_pytest-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2b7bba1ee7afe798113c119185c0794229cfdebb8a27b83bc3f361fd6a6895a6
MD5 ad2fe288c7de2de6297d98b7c6005f11
BLAKE2b-256 1846f8e483f2bdcb62f07426f130e89a52cbc8aef179c638a7c3ba3ddf35f44e

See more details on using hashes here.

Provenance

The following attestation bundles were made for aimock_pytest-0.2.0.tar.gz:

Publisher: publish-pytest.yml on CopilotKit/aimock

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for aimock_pytest-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9e08fed630402654e71067dc3ad17773f6fdb6a69897d5d822f077dec2d91ffc
MD5 9eef106052c79a866f98251197467999
BLAKE2b-256 d08565addaf5267eb363cb0ffa2b395018738354cf92438e438e7581f43990c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for aimock_pytest-0.2.0-py3-none-any.whl:

Publisher: publish-pytest.yml on CopilotKit/aimock

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page