Skip to main content

jevkit-pytest

Record and replay TypeSafe Jev requests in pytest.

A model call in a test is slow, costs money, needs a key in CI, and can change its answer under you when the alias moves. The fix is the one VCR established for HTTP: record real responses once, replay them forever, re-record on purpose.

Unofficial and unaffiliated with TypeSafe.

pip install jevkit-pytest

Use

def test_routes_billing_questions(jev_cassette):
    response = jev_cassette.system_one(
        "I was charged twice for the same order",
        {"team": {"type": "choice", "instructions": "Which team should handle this",
                  "criteria": {"billing": "Payment issues", "technical": "Bugs",
                               "unknown": "None apply"}}},
    )
    assert response.answers["team"]["choice"] == "billing"

Record the first time, then never again:

pytest --jev-record       # record anything missing
pytest                    # replay only; a miss is a failure
pytest --jev-rerecord     # replace every recording

To record you need a live client. Supply one by overriding the jev_client fixture in your conftest.py:

import pytest
from typesafe_sdk import TypeSafeClient

@pytest.fixture
def jev_client():
    with TypeSafeClient() as client:
        yield client

Replay-only runs need no client and no API key, which is the point: CI stays green without a secret.

Assertions that explain themselves

from jevkit_pytest import assert_answer, assert_confident

assert_answer(response.answers["team"], "billing", min_probability=0.6)
assert_confident(response.answers["urgency"], 0.8)

On failure these print the whole distribution, because a 0.51/0.49 split and a 0.99/0.01 split are different bugs and assert x == y cannot tell them apart.

assert_confident uses the API's confidence for Choice and Score. A Noul carries none, so its distance from 0.5 is used and the message says which it used.

Cassettes are golden sets

A cassette is a .jevl file, the same format jevkit-drift, jevkit-bench and jevkit-calibrate read. So the recordings your tests already make are a golden set you can replay against the next model version:

jevkit-drift tests/cassettes/test_routes_billing_questions.jevl candidate.jevl

That is the whole reason the format was defined before any of these packages.

License

MIT

Metadata

Release files for jevkit-pytest 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jevkit-pytest 0.1.0
File Size Uploaded
jevkit_pytest-0.1.0.tar.gz 8.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jevkit-pytest 0.1.0
File Interpreter ABI Platform
jevkit_pytest-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.7 kB

Release files / jevkit_pytest-0.1.0.tar.gz

Download URL jevkit_pytest-0.1.0.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
16b1673addad7a90abf93db8e7b17509a3f0986393f81b6140b307bcdabd5584
BLAKE2b-256 checksum
How to use checksums
97b5feabcb5c34a1ada8771f6e484028217bfeb32fecdc4f734a7491dd920edc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Release files / jevkit_pytest-0.1.0-py3-none-any.whl

Download URL jevkit_pytest-0.1.0-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1b30565e1046e190e22561fce1875fd137f0c3fe31c0cbe0cd6b45067d367aeb
BLAKE2b-256 checksum
How to use checksums
70536fd9829d0f0a8e1dac1b14bee5a888ae10ea4f8da23ec74fc7565c123c02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page