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.1.0.tar.gz (8.1 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.1.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file aimock_pytest-0.1.0.tar.gz.

File metadata

  • Download URL: aimock_pytest-0.1.0.tar.gz
  • Upload date:
  • Size: 8.1 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.1.0.tar.gz
Algorithm Hash digest
SHA256 b0cbc98f87d338b711e0f21e2b792c5aba305d61469e7d15f8c98ecf5f8f6e4d
MD5 29071ac7b89807e157c2a7a93dea0730
BLAKE2b-256 1ea1bda6351f217ae635330fc5c08ae9ebf926510ba1d617948e693ba77b5edf

See more details on using hashes here.

Provenance

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

Publisher: publish-pytest.yml on CopilotKit/llmock

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.1.0-py3-none-any.whl.

File metadata

  • Download URL: aimock_pytest-0.1.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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 86f5b47d45ddbf4e00c0aaf5acc225172272cecd43ea2bdda23357f21e194af7
MD5 8ca6f97f1d5ad5098d7ec57dcb1be417
BLAKE2b-256 df8190d388552b573bcf1b952b96c8eb43ed8f8d42c63b165a08de75209b6864

See more details on using hashes here.

Provenance

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

Publisher: publish-pytest.yml on CopilotKit/llmock

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