pytest-admission
Project-configured admission for pytest. Requires Python 3.11+ and pytest
8.3.4 through 9.x. Licensed under the MIT license in LICENSE.
Install
python -m pip install pytest-admission
The pytest11 entry point loads the plugin automatically. For a source checkout:
python -m pip install -e '.[test]'
python -m pytest -q
CI runs Python 3.11 and 3.12 with both pytest 8.3.4 and the newest available
pytest below 10. Acceptance tests use isolated pytester subprocess sessions
and a file-writing stand-in, not a solver or compiler.
Admission command
pytest-admission check --base <review-base>
# Source-checkout alternative:
python -m pytest_admission.cli check --base <review-base>
The command collects the full project once, never running test bodies or
fixtures. Configured workflow sources still have their own collection-only
subprocesses. It ignores pytest addopts and PYTEST_ADDOPTS so they cannot
narrow the population. Each failing check prints one line prefixed with its
arm (selection, contract, or simulation); collection/configuration errors
also fail closed. Exit status is 0 on a clean collection and 1 on failure.
--base defaults to HEAD; --root <directory> selects another project.
The existing pytest-admission record command remains the sole record writer.
Release
Version 0.1.1 is released by pushing tag v0.1.1 after configuring the
repository's PyPI trusted publisher for .github/workflows/release.yml and
the GitHub pypi environment. The workflow builds the wheel and source
distribution without publishing credentials, checks the tag against package
metadata, then publishes through PyPI's trusted-publishing action. Tagging
and configuring/approving publication are maintainer actions.
Declare launch sinks
Put configuration in the pyproject.toml at pytest's root directory:
[tool.pytest-admission]
sinks = ["myproject.launch:compile_model", "myproject.runner:Runner.launch"]
[tool.pytest-admission.relax]
env = "PROJECT_BUILD_VENUE"
values = ["toolchain"]
Each sink is importable.module:qualified.callable; dotted attributes after the
colon can name methods. Declare the callable at the entry point used by the
project, not a copied alias. Target modules must be importable at session
configuration time (use an installed package or pytest's pythonpath setting).
Importing a target module must not itself launch work.
Before collection, pytest_configure imports and resolves every declared sink,
then replaces each with a callable that fails with
pytest-admission: refused sink <configured name>. No original call is made.
A call from a fixture fails during setup. Originals are restored when pytest
cleans up its configuration, including failed sessions.
The refusal is armed by default in every session. Only an exact, case-sensitive
match between the configured environment variable and one of values leaves
the original callables untouched. Missing, empty, misspelt, and other
unrecognised tokens do not relax it. Without relax, sinks remain armed.
The plugin is a test guard, not a sandbox: it does not intercept aliases that
were already copied before configuration or launches outside declared sinks.
No table (or no sinks) means no declared sinks. Configuration accepts only
sinks, relax, project_roots, simulation_list, registry, record,
jobs, launchers, and hand_kept_lists;
relax accepts only env and values. Unknown keys,
malformed tables, malformed callable names, non-string or duplicate array
entries, missing relaxation fields, and unresolvable/non-callable sinks fail
configuration with an error naming the field or sink. sinks may be empty;
relax.values must contain at least one non-empty string. Environment variable
names use letters, digits and underscores and cannot start with a digit.
Collection reach analysis
project_roots = ["."] names directories relative to the pytest root (the
default is the whole project). simulation_list = ["tests/test_model.py::test_run"]
lists admitted simulation-bearing node IDs; shell-style patterns are accepted,
including for parametrized IDs. The default list is empty. Being listed does
not relax runtime refusal: only the venue token does that.
Collection walks test bodies and every fixture in each item's closure, following
statically resolved Python calls inside those roots. Reaching a declared sink,
or an ambiguous call beneath a declared sink module, places a test in the
simulation-bearing tier; otherwise it is fast. Unlisted simulation-bearing
tests fail collection admission. Dynamic string-based getattr calls are not
resolved: they can remain fast and still be refused at runtime.
Every session writes .pytest_cache/admission/<session-id>.json, keyed by node
ID, with tier, sinks, routes (call chains), and unresolved_calls. The
artifact is written even when admission fails. Tier is also exposed as the
admission_tier item user property. The walk does not execute user calls and is
not a proof of absence of simulation; runtime refusal remains independent.
Contract admission
Enable the contract check by configuring both project-relative paths:
[tool.pytest-admission]
registry = "tests/contracts.toml"
record = "tests/admission_record.json"
The registry is a TOML contracts table keyed by contract name (its values
may hold descriptions), or contracts = ["name", ...]. An empty file is an
empty registry. Mark each covered test with @pytest.mark.contract("name").
Unknown names, multiple markers on one item, malformed markers, and registered
names with no collected item fail admission.
Run the whole collection with pytest --base <revision>. Git's committed
<revision>...HEAD diff defines added or edited tests; their function spans
include decorators. Unmarked changed definitions fail. --base defaults to
HEAD for an unchanged-tree run; pass the review base to check a change.
The pytest project root may be a subdirectory of the Git repository; changed
paths are resolved from the repository toplevel, not the project root.
The unmarked count counts collected items, including each parametrized case,
and must equal the record's unmarked_tests. It may not rise above the base
record, and removing an unmarked item requires lowering the record in the
same change. A zero record permits no unmarked item.
pytest-admission record
# Source-checkout alternative:
python -m pytest_admission.record record --root .
This command is the only record writer. It collects without running test
bodies or fixtures, initializes a missing record, or lowers an existing count.
It refuses an increase and leaves the file untouched on collection or
admission errors. JSON gaps (the selection-coverage record) is preserved.
Ordinary pytest sessions never rewrite the admission record. Commit the
record together with the tests that lower it.
Selection coverage
Declare up to six logical jobs, each with one or more workflow sources:
[[tool.pytest-admission.jobs]]
name = "fast"
capabilities = ["network"]
sources = [{ workflow = ".github/workflows/tests.yml", job = "unit" }]
[[tool.pytest-admission.hand_kept_lists]]
path = "tests/allowlist.toml"
format = "toml"
field = "tests.nodes"
Each source reads its pytest arguments from that workflow job's run steps.
Literal pytest, python -m pytest, and prefixed commands such as uv run pytest are supported. Workflow/job/step working directories and simple cd
commands are respected. $NAME and ${NAME} in pytest arguments resolve from
the same step's env, then the job's env, then workflow env (never the host
environment). Scalar values remain one argument, including quoted marker
expressions. An env value may use ${{ matrix.KEY }} from a finite
strategy.matrix: literal axes, include and exclude are expanded, and
distinct argument sets are unioned. This supports step env declarations such
as SHARD: ${{ matrix.shard }} with --ci-shard "${SHARD}/${SHARD_COUNT}".
Single-quoted or backslash-escaped dollar signs in pytest arguments fail closed
instead of being expanded; ordinary double-quoted references remain supported.
Unknown references, dynamic matrices, other workflow expressions and command
substitutions fail closed. Workflow shell, test bodies and launcher scripts
are never executed by the check; collection does import tests and conftests.
Every source is collected in a fresh subprocess with its paths, markers,
deselections and plugin options intact.
File-descriptor redirects such as 2>&1, including before | tee log, do not
become positional pytest arguments.
Only an unquoted number directly adjacent to < or > is an fd prefix.
Numeric pytest arguments separated from the redirect, such as -n 4 > log
or --maxfail 2 > log, are preserved.
Set launchers = ["scripts/collect_launcher.py"] in the main admission table
for a command whose pytest arguments follow --. Sources within one logical
job are unioned, then all logical jobs are unioned. Fewer than six jobs permits
only gaps already in the HEAD-committed admission record's JSON gaps;
six jobs permits no gaps. A second source is not another job. The check does
not rewrite the record, and jobs require the configured registry/record pair.
An unconditional skip or literal-true skipif fails collection.
Conditions may be positional or supplied as condition=; false boolean and
string-expression conditions are not classified as unconditional skips.
A capability skip uses @pytest.mark.skipif(condition, capability="network", reason="...");
at least one configured logical job must declare that capability.
List formats are lines (one ID per nonblank line, # comments permitted),
toml (a dotted field selecting a string array or projecting a string field
from an array of tables, e.g. field = "node.id" for [[node]] entries),
or python (field naming one module-level literal tuple/list, read by AST
without importing it). Missing fields and non-string or empty IDs fail closed.
Entries must resolve to collected items; pytest parent selectors, including
unparametrized function IDs, are accepted. Missing positional workflow node
selectors also fail source collection. All checks use the full population
passed to admission, so invoke admission without -k, -m, or path narrowing.
Metadata
Release files for pytest-admission 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytest_admission-0.1.1.tar.gz | 30.8 kB | With provenance | Details for pytest_admission-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_admission-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for pytest_admission-0.1.1-py3-none-any.whl |
Total release size: 56.6 kB
Release files / pytest_admission-0.1.1.tar.gz
| Download URL | pytest_admission-0.1.1.tar.gz |
|---|---|
| Size | 30.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
feb2d96ac5401fe0ba1c2d9fb73d126fce98ff642465c72c6817633b5a10d227
|
|
BLAKE2b-256 checksum How to use checksums |
9aebd12d2fe159ed0c43d6b4943ee1a2e60a540798839ad69a9f50f6bef8b216
|
| 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 Dec 1, 2026.
Transparency logRelease files / pytest_admission-0.1.1-py3-none-any.whl
| Download URL | pytest_admission-0.1.1-py3-none-any.whl |
|---|---|
| Size | 25.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
771466de1104321b5f91f43f4753e4d61055bb3b10c5c3c4e5bb38c1b90b90ea
|
|
BLAKE2b-256 checksum How to use checksums |
6b2d9a028504803f04a438386f0a2d2d9309c38159da7ad97be86852b31b9ed4
|
| 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 Dec 1, 2026.
Transparency logSecurity for pytest-admission 0.1.1
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.
Attestation for pytest_admission-0.1.1.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 Dec 1, 2026.
Transparency logA 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.