pytest-quint-connect
Model-based testing for Python under pytest. Quint generates histories from your specification; pytest-quint-connect replays every step against your real Python implementation and compares the state you read back with the state the model expects.
Why: coding agents change code faster than anyone can review it. Write your high-level rules once as a small Quint model you can test in the abstract; pytest-quint-connect connects your implementation to it, so every change, by a person or an agent, is checked against the rules rather than against tests the same change may have rewritten. Why, with real output · Tutorial · Run it in CI
Read the documentation · Related tools
This is a community Python integration in the spirit of Quint Connect (Rust) and Quint's model-based testing guide. It is not an official Quint project and is not endorsed by its maintainers.
test_lru_contract.py::test_lru_cache[witness-evictsLeastRecentlyUsedTest] FAILED
Quint contract 'lru-cache': implementation state differs from the model
trace: .artifacts/quint-connect/lru-cache/witness-evictsLeastRecentlyUsedTest-0.itf.json
state: 3 after action fetch(key='a', value=0)
seed: 7
4 difference(s):
entries[0].key: values differ
expected: 'b'
actual: 'a'
...
reproduce: pytest test_lru_contract.py::test_lru_cache --quint-replay .artifacts/quint-connect/lru-cache/witness-evictsLeastRecentlyUsedTest-0.itf.json
Quick start
Install the plugin, plus Node.js 22+ with npm. On first use the plugin installs its
locked Quint 0.33.1 into a per-user cache. To use your own Quint, pass --quint PATH
or set QUINT.
pip install pytest-quint-connect
To try unreleased changes, install from Git instead:
pip install "pytest-quint-connect @ git+https://github.com/gigaverse-app/pytest-quint-connect".
Generate a typed driver base from the model, then declare the contract:
pytest-quint-connect codegen quint-connect.json -o lru_cache_driver.py
# test_cache_contract.py
from pytest_quint_connect import quint_contract
test_cache = quint_contract("quint-connect.json", driver="cache_driver")
Subclass the generated base. It has one typed method per model action and an
observe() typed as the model's observed state, so a type checker flags a driver
that has drifted from the spec:
# conftest.py
import pytest
from lru_cache_driver import LruCacheDriver, Read, View # generated
from my_cache import LRUCache
class CacheDriver(LruCacheDriver):
def __init__(self) -> None:
self.cache, self.last = LRUCache(2), {"tag": "NoRead"}
def init(self) -> None: ...
def inspect(self) -> None: ...
def store(self, key: str, value: int) -> None: # apply one model action to the real code
self.cache.put(key, value)
def fetch(self, key: str) -> None:
value = self.cache.get(key)
self.last: Read = {"tag": "Miss"} if value is None else {"tag": "Hit", "value": value}
def observe(self) -> View: # read the real state back
return {"entries": [{"key": k, "value": v} for k, v in self.cache.items()], "lastRead": self.last}
@pytest.fixture
def cache_driver():
return lambda context: CacheDriver() # called once per history: fresh state each time
pytest --quint-require-complete
A hand-written driver that implements step(step) and observe() works too; see
drivers.
examples/lru_cache is the complete version. It checks a
list-based cache and an OrderedDict refactor against the same generated
histories, catches a cache whose reads forget to refresh recency, and runs from
the installed wheel in CI.
What a contract run does
quint-connect.json ──► quint typecheck ──► quint test (named witnesses) ──► witness-*.itf.json ─┐
└──► quint run --mbt (seeded samples) ──► sample-*.itf.json ─┤
▼
pytest: test_x[witness-…] test_x[sample-N] ──► fresh driver per history ──► step → observe → compare
test_x[mutant-…] every trace through the mutant; only an observed mismatch counts
test_x[coverage] every declared action reached
▼
.artifacts/quint-connect/results.json, traces, logs, mismatch-*.json
- Real pytest cases. Each witness, sample, mutant and the coverage check is a
parametrized case: selectable with
-k, listed by--collect-only, reported in JUnit (withquint_trace,quint_seedandquint_detected_byproperties), with ordinary fixture setup and teardown. - Fresh Quint, every run. Traces are regenerated from the model with the manifest's seed and bounds; the output directory is emptied first. Collection never runs Quint; a Quint failure is a setup error for every case of that contract.
- Mutation controls. A mutant passes only when some generated history produces an observed-state mismatch. An exception while building or running the mutant fails the case: it is not detection.
- Complete or not. With
--quint-require-complete, the session fails unless every contract inquint_required_contractsran every case and passed. A-k-filtered run is recorded aspartial, a replay asreplay-only; a crash leavesrunning, never an earlierpassed. - Actionable failures. A mismatch names the trace, state, action and arguments,
a field-level expected/actual difference, the seed and a command that replays that
exact trace (
--quint-replay, optionally--quint-mutant). An exception from the driver keeps its own type and message and gains the same location as a note.
To / Read
| To | Read |
|---|---|
| See why, with real output | docs/why.md |
| Build your first contract step by step | docs/tutorial.md |
| Make contracts a required CI check | docs/ci.md |
| Set it up with an agent | skills/pytest-quint-connect/SKILL.md |
| Write a manifest | docs/manifest.md |
| Write a driver and choose a step convention | docs/drivers.md |
| Know what a passing run does and does not prove | docs/limits.md |
| Configure options and read the receipt | docs/reference.md |
| See it on production integrations | pytest-obligation's report-merge contract, pytest-selective's selection contract |
Measured
| Contract | Histories | Cases | Mutants detected | Notes |
|---|---|---|---|---|
| LRU cache example | 15 (3 witnesses, 12 samples) | 17 per implementation | 1/1 | list and OrderedDict implementations pass; the stale-read cache fails 4 of 15 histories |
pytest-obligation merge_reports |
21 (5 witnesses, 16 samples) | 28 | 6/6 | same 21 histories, state for state, as the runner it replaced |
| pytest-selective's selection | 19 (7 witnesses, 12 samples) | 23 | 3/3 | each step is a real Git commit selected by affected(); the mutants drop base-tree edges, stop after direct importers and ignore global inputs |
| This plugin's own receipts | 8 (4 witnesses, 4 samples) | 13 | 4/4 | each step is a real pytest session; the mutants break the plugin's completeness and receipt logic |
Quint 0.33.1, TypeScript backend. See PROVENANCE.md for where the engine came from and how the baseline was reproduced.
Duplicates kept out
Local hooks and the required PR check prevent new copies. The weekly audit records progress against the accepted backlog. Setup and cleanup workflow.
Reviewed duplication debt · Counts from the committed baselines.
| Accepted pairs | Remaining | Retired | Dismissed |
|---|---|---|---|
| Functions | 5 | 0 | 0 |
| Models | Not initialized | — | — |
Accepted backlog · Weekly audit
Retired means a side was removed, or (functions only) the judge now finds the pair separate. It is not a count of refactors. Dismissals stay separate; an uninitialized model baseline is unknown.
Related projects
| Project | What it does |
|---|---|
| pytest-obligation | Conformance proofs for background work that must survive lost messages and dead workers |
| Due | Durable obligations for Python: PostgreSQL remembers what is owed |
| pytest-selective | Explainable test impact analysis for pytest |
| CI-esta | CI observability and honest merge gates |
| dry-lint | Finds code that re-implements what the codebase already does |
License
Apache 2.0. See CONTRIBUTING.md to work on pytest-quint-connect itself and RELEASING.md for publishing.
Pull requests run only the test lanes and test files a change can affect, chosen by pytest-selective. CI-esta reports this repository's CI timing, keeps its test durations and owns its required gate. Neither is a dependency of pytest-quint-connect. See how CI runs here.
Metadata
Release files for pytest-quint-connect 0.2.0
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_quint_connect-0.2.0.tar.gz | 244.8 kB | With provenance | Details for pytest_quint_connect-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_quint_connect-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for pytest_quint_connect-0.2.0-py3-none-any.whl |
Total release size: 297.6 kB
Release files / pytest_quint_connect-0.2.0.tar.gz
| Download URL | pytest_quint_connect-0.2.0.tar.gz |
|---|---|
| Size | 244.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e29836917b91e3c75839234b03d0ce1e1f8f0a1c1ae660d8afc7310fdc7be38c
|
|
BLAKE2b-256 checksum How to use checksums |
6863000e92e2c581be6026b9138d51f522e35d91841af7c8d4d4b1d968f6b0a6
|
| 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 8, 2026.
Transparency logRelease files / pytest_quint_connect-0.2.0-py3-none-any.whl
| Download URL | pytest_quint_connect-0.2.0-py3-none-any.whl |
|---|---|
| Size | 52.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fa8d8ac112040b53c36528dbf830b0b7336f51589b8c8405a891b3b0e7f27daf
|
|
BLAKE2b-256 checksum How to use checksums |
6339df7d8a823e7110cf2bbcbb1e065a44ff4ba4ed0232175a55d9d91dbac02a
|
| 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 8, 2026.
Transparency logSecurity for pytest-quint-connect 0.2.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.
Attestation for pytest_quint_connect-0.2.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 8, 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.