
pytest-obligation

Read the documentation · Related tools
PR evidence report: what passed, what is missing, what to fix
Don’t lose orders, money, receipts, or work when the happy path breaks
Your app may commit an order, charge a customer, schedule a task, send a
receipt, publish to Kafka, or call Shopify. A worker can die one line later; a
broker reply can be lost; a retry can run the external effect twice. Ordinary
tests usually exercise only the path where none of that happens.
pytest-obligation generates tests for work your application cannot afford to
lose or repeat. Bind an ObligationContract to your real workflow and recovery
path, yourself or with a coding agent. The harness generates standardized tests
for crashes, retries, lost messages, and competing operations, exposing failure
cases you might never think to write by hand. Its fault injection interrupts
commits, workers, messages, and external calls, then checks whether recovery
reaches the right outcome without lost work or duplicate effects.
The agent can use the same fault-injection infrastructure to add focused tests
for your application's particular risks. The core accepts plain Python
callables: it assumes no framework, database, queue, or business domain.
It integrates as a pytest plugin in your existing test suite and CI. Read the
pytest plugin guide
for automatic discovery, test selection, reports, and configuration.
Coming from distributed systems and familiar with Jepsen? pytest-obligation
brings a similar approach to your application's workflows. Read
Jepsen-style fault testing for application work.
What it finds
- Lost work: a Django transaction commits an order, but a Celery task or
Kafka message is never published; a dead worker's task is never picked up.
- Duplicate effects: a retry sends two receipts, charges twice, or repeats
an external API call after the first result became uncertain.
- Wrong final state: a stale worker overwrites a newer result, a checkout
takes a payment without creating an order, or cleanup deletes work still owed.
These are not just hypothetical failures. Runs against Saleor, Wagtail,
procrastinate, DBOS, RQ, and Celery show the real code,
failure timing, observed result, and—in several cases—a fix that makes the
same proof pass. For example, a Saleor Payments API checkout can capture a
payment and lose the order when the worker dies between those steps; a DBOS
notification step can send twice when it is replayed.
What a finding looks like
One crash history compares the normal outcome with the outcome after a
specific interruption:
pytest_obligation.HistoriesDiverged: orders: handoff 'place order': normal operation reaches
('SENT', 1), but these histories reach something else: {'worker died after external call 1':
('SENT', 2)}. Work was lost or repeated. ...
The second send is visible instead of being hidden behind a green happy-path
test. Known, independently reproduced gaps remain strict xfails; a change
that fixes one turns it red so the finding must be re-evaluated. See
how crash histories work and
what a green result means.
Stronger tests without hand-writing more tests