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: the test is retried up to twice, 60 seconds apart, except for a gated-dataset error (GatedRepoError, or DatasetNotFoundError mentioning a gated dataset), which is not retried and is reported as a skip. The test also runs when HF_TOKEN is unset or blank, and the terminal summary then says how many huggingface tests ran without a token. See Gated Hugging Face datasets and strict mode to fail on a gated-dataset error or a missing token instead.
  • docker and posix_only: skipped on Windows.

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

Gated Hugging Face datasets and strict mode

By default, a gated-dataset error in a huggingface test is reported as a skip. This keeps local runs green for contributors who have not accepted a dataset's terms. This applies whether the error is raised in the test body or in a fixture during setup, for example a module-scoped fixture that fetches dataset info.

A huggingface test also runs when HF_TOKEN is unset or blank, so tests of public datasets pass without a token. The terminal output then ends with a "Hugging Face token" section:

============================== Hugging Face token ==============================
HF_TOKEN is not set: 3 huggingface test(s) ran without authentication. A gated-dataset error is reported as a skip, a test that needs a private dataset fails, and the Hub applies lower rate limits to requests without a token.

The count covers the tests that started. It leaves out tests that -m or -k deselected and tests that a gate skipped. Each counted test has an ("hf_no_token", "") entry in the user_properties of its setup report. Without a token the Hub reports a private dataset as missing, so a test that needs one fails after its two retries.

Strict mode is for CI jobs that are expected to have access. It is off by default and can be turned on in three ways:

  • Environment variable: REQUIRE_HF_ACCESS=1
  • Command-line flag: pytest --require-hf-access
  • Ini option: require_hf_access = true under [tool.pytest.ini_options]

A non-empty REQUIRE_HF_ACCESS value wins over the flag, and the flag wins over the ini option. For example, REQUIRE_HF_ACCESS=0 turns strict mode off even when the ini option is true.

In strict mode:

  • A gated-dataset error fails the test instead of being skipped. An error raised in a fixture is reported as a setup error, with the same tag and summary entry.
  • Collecting huggingface tests with HF_TOKEN unset or blank stops the run with a usage error, where the default mode runs them. Under pytest-xdist, each huggingface test fails at setup with the same message instead, because a usage error on a worker would crash the run.
  • The terminal output ends with a "Hugging Face access denied" section that lists the dataset page to visit for each gated dataset, such as https://huggingface.co/datasets/<repo_id>. When the repo id is unknown, it lists the test's node id followed by "(dataset unknown)".

CI tooling can find these failures in the report. Each failed report has a ("hf_access_denied", "<repo_id>") entry in its user_properties, and the value is an empty string when the repo id is unknown. --report-log writes it to the JSON lines file under user_properties.

Gated errors are never retried, in either mode. Other errors are still retried twice, 60 seconds apart.

The dataset viewer helpers in pytest_inspect_evals.huggingface check access when the viewer API returns a non-200 response. If the dataset is gated, they raise the Hub's GatedRepoError, which is handled as described above. If the dataset is missing or private, they raise RepositoryNotFoundError, which is an ordinary failure. For any other non-200 response, or if the access check itself fails, they raise an AssertionError as before.

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"

isolated_inspect_store runs for every test without being requested. It gives each test a fresh inspect_ai Store and restores the previous one afterwards. Outside of eval(), store() and store_as() use one Store for the whole pytest process, so data a test writes there, for example through a StoreModel-backed tool, would otherwise reach every later test. inspect_ai copies and compares the active store on every solver step, so that data also slows later tests that run solvers or agents directly. A test that needs data to persist between tests should keep it in its own fixture instead.

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

Three fixtures use inspect_ai internals that have no public equivalent: set_model_roles calls inspect_ai.model._model.init_model_roles, isolated_inspect_store calls inspect_ai.util._store.init_subtask_store, 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.4.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.4.0
File Size Uploaded Provenance Actions
pytest_inspect_evals-0.4.0.tar.gz 26.0 kB With provenance Details for pytest_inspect_evals-0.4.0.tar.gz

Built distribution (wheel)

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

Total release size: 54.4 kB

Release files / pytest_inspect_evals-0.4.0.tar.gz

Download URL pytest_inspect_evals-0.4.0.tar.gz
Size 26.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7daf3674ada40b8e6d0d6d38a83d9cfbf2c3415c9bf070f9ddae617abcff84d0
BLAKE2b-256 checksum
How to use checksums
e2bd1de0d5cf8197c28fe4aff4176d901d446cfb7b24ac855d0febb2f89beabb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 11, 2026.

Transparency log

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

Download URL pytest_inspect_evals-0.4.0-py3-none-any.whl
Size 28.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bded1bdda6839fad6f6e7318a041864af769e0ad57bfd787c35a0ef722628bfd
BLAKE2b-256 checksum
How to use checksums
75da458c174ff4e159653916c2a8f02b8e7a19a8ff01aefb676b6abecfbd8ef3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 11, 2026.

Transparency log

Security for pytest-inspect-evals 0.4.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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pytest_inspect_evals-0.4.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 Nov 11, 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.

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