Skip to main content

pytest-inspect-evals

A pytest plugin with the test gates, fixtures and helpers shared by Inspect AI evaluation repos. It started as the shared test code in inspect_evals. Installing it replaces a copied conftest.py and tests/utils/ with one pinned dependency.

Install

uv add --dev pytest-inspect-evals
# or, to use the Hugging Face dataset helpers:
uv add --dev "pytest-inspect-evals[huggingface]"

The plugin loads automatically. There is nothing to add to conftest.py.

Test gates

Four markers mark tests that are skipped unless you switch them on.

Marker CLI flag Env var Pytest config option Default
slow --runslow RUN_SLOW_TESTS inspect_evals_slow off
dataset_download --dataset-download RUN_DATASET_DOWNLOAD_TESTS inspect_evals_dataset_download off
k8s --runk8s RUN_K8S_TESTS inspect_evals_k8s off
gpu --rungpu RUN_GPU_TESTS inspect_evals_gpu off

The env var wins when it is set to a non-empty value: 1, true, yes or on switch the gate on, anything else switches it off. Otherwise the CLI flag switches it on. Otherwise the config option decides, and the default is off. An empty env var counts as unset.

To run a gate by default in your repo, set its option in pyproject.toml:

[tool.pytest.ini_options]
inspect_evals_dataset_download = true

Three more markers have fixed behaviour:

  • huggingface: skipped when HF_TOKEN is unset or blank. Otherwise the test is retried up to twice, 60 seconds apart, and a gated-dataset error (GatedRepoError, or DatasetNotFoundError mentioning a gated dataset) is reported as a skip.
  • docker and posix_only: skipped on Windows.

The plugin registers all seven markers, so they work under --strict-markers without any config.

Adding your own gate

skip_if_marker_present is the function the plugin uses. Call it from your conftest.py for repo-specific gates:

from pytest_inspect_evals.gates import skip_if_marker_present


def pytest_addoption(parser):
    parser.addoption("--custom-smoke", action="store_true", default=False)


def pytest_configure(config):
    config.addinivalue_line("markers", "custom_smoke: tests that call a live service")


def pytest_collection_modifyitems(config, items):
    skip_if_marker_present(
        config,
        items,
        marker="custom_smoke",
        cli_flag="--custom-smoke",
        env_var="RUN_CUSTOM_SMOKE_TESTS",
        reason="custom_smoke tests disabled (set RUN_CUSTOM_SMOKE_TESTS=1 or pass --custom-smoke)",
    )

Fixtures

set_model_roles returns a context manager that sets model roles, for testing scorers that call a grader model:

def test_judge_scorer(set_model_roles):
    with set_model_roles(grader=get_model("mockllm/model")):
        ...

mock_docker_sandbox stubs the Docker sandbox lifecycle, so an eval with sandbox="docker" runs without Docker. Combine it with mocked sandbox().exec results to test a scorer end to end:

def test_e2e(mock_docker_sandbox):
    [log] = eval(my_task(), model="mockllm/model")
    assert log.status == "success"

Helpers

  • pytest_inspect_evals.assertions: assert_task_structure, assert_eval_success, run_single_sample_eval, get_metric_value.
  • pytest_inspect_evals.solvers: mock_solver_with_output, run_command.
  • pytest_inspect_evals.sandbox: MockExecResult, create_sandbox_tool_task, assert_sandbox_test_passed.
  • pytest_inspect_evals.metrics: run_metrics, assert_agreeing_epochs_change_nothing, MetricEvalError. These run custom metrics through the real epoch reducer, the way an eval does.
  • pytest_inspect_evals.huggingface (needs the huggingface extra): assert_huggingface_dataset_structure, get_dataset_infos_dict, assert_huggingface_dataset_is_valid, assert_dataset_contains_subsets, assert_dataset_has_columns. These check a dataset's schema through the Hugging Face dataset viewer API without downloading it.

Migrating from a copied conftest

If your conftest.py came from inspect_evals or inspect-evals-template, remove what the plugin now provides:

  • the pytest_addoption lines for --runslow, --dataset-download, --runk8s and --rungpu;
  • the matching skip logic in pytest_collection_modifyitems;
  • the seven markers above from your markers = config (keeping them is harmless).

If you keep the options, pytest stops at startup with argparse.ArgumentError: argument --runslow: conflicting option string: --runslow.

Private inspect_ai APIs

Two fixtures use inspect_ai internals that have no public equivalent: set_model_roles calls inspect_ai.model._model.init_model_roles, and mock_docker_sandbox patches inspect_ai.util._sandbox.docker.docker.DockerSandboxEnvironment. A future inspect_ai release could break them.

Development

uv sync
uv run pre-commit install   # optional: run the lint stack on every commit
uv run pytest
uv run basedpyright src

Each pull request adds a changelog fragment rather than editing CHANGELOG.md, so concurrent PRs don't conflict. Run uv run scriv create, uncomment the sections that apply in the new file under changelog.d/, and commit it with the change, or delete it if the change needs no entry. To release, run the Prepare release workflow from the Actions tab. It bumps version in pyproject.toml, collects the fragments into CHANGELOG.md, and opens a release pull request, whose CI starts once you click Approve workflows to run on it; merging it tags the release. It needs Settings → Actions → General → Allow GitHub Actions to create and approve pull requests. By hand, the same is uv version --bump minor and uv run scriv collect.

Linting (ruff, zizmor, mdformat) runs via pre-commit; CI runs the same stack plus basedpyright and pytest via the shared python-ci reusable workflow.

Releasing

See RELEASING.md.

Metadata

Release files for pytest-inspect-evals 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 pytest-inspect-evals 0.1.0
File Size Uploaded Provenance
pytest_inspect_evals-0.1.0.tar.gz 20.8 kB With provenance Details

Built distribution (wheel)

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

Total release size: 44.7 kB

Release files / pytest_inspect_evals-0.1.0.tar.gz

Download URL pytest_inspect_evals-0.1.0.tar.gz
Size 20.8 kB
Tags Source
SHA-256 checksum
How to use checksums
fbc3dee6987776f10b58c879ec94dd475c9636e60cd6573e5f3f24fd884e73b2
BLAKE2b-256 checksum
How to use checksums
ed267c51f97e6c1d9553fc7a921720d3a90ea80f158c3a311aeeafa23ac48af7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 9, 2026.

Transparency log

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

Download URL pytest_inspect_evals-0.1.0-py3-none-any.whl
Size 23.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c126894c6c04ec67fb17ebb554637faf7e6964926d69be4d0136bb9212e60120
BLAKE2b-256 checksum
How to use checksums
b1ff5eb134b7e70f227dd912d0d7a02a1387eca992e9871ee4c41c034fcb62b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 9, 2026.

Transparency log

Security for pytest-inspect-evals 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pytest_inspect_evals-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 9, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

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