Skip to main content

focused-spec-scenarios

Independent executable Given/When/Expect scenarios for Python 3.11+. The SDK uses only the Python standard library at runtime; it does not require focused-spec, OpenSpec, pytest, or another test framework.

Install and execute

python -m pip install focused-spec-scenarios
from focused_spec_scenarios import Driver, Scenario, verify_specification

scenario = Scenario(
    id="account.deposit",
    name="A deposit increases the balance",
    given={"balance": 100},
    when={"cents": 25},
    expect={"balance": 125},
)
driver = Driver(
    given=lambda initial, context: dict(initial),
    when=lambda account, command, context: {
        "balance": account["balance"] + command["cents"]
    },
)
actual = verify_specification(driver, scenario)
assert actual == {"balance": 125}

The expectation is authored independently of the driver. verify_specification accepts synchronous drivers and returns the actual observation. verify_specification_async awaits synchronous or asynchronous operations and can be used directly from an existing asyncio event loop.

Public API

Scenario(id, name, given, when, expect) declares one outcome. define_suite(*scenarios) validates a nonempty suite and rejects duplicate IDs. Driver(given, when, cleanup=None) binds application operations. The preparation operation receives Given and a DriverContext; the action receives the prepared subject, When, and that context. verify_specification and verify_specification_async accept optional on_event and cancelled callbacks.

IDs are exact, contain non-whitespace, and have no control characters. Names are nonblank. Scenario data is limited to null, booleans, strings, integers, finite floats, lists, tuples, and string-keyed dictionaries containing the same supported values. Cycles, non-string keys, sets, custom objects, and non-finite numbers are rejected before driver execution. Python annotations help static checking; runtime validation remains authoritative.

Comparison is recursive and type-aware: True does not equal 1, tuple and list differ, collection order matters, and missing keys differ from keys with None. Driver inputs are deep-copied from the reusable declaration. ScenarioMismatch exposes scenario identity and independent expected/actual snapshots.

Cleanup, cancellation, and events

After preparation succeeds, optional cleanup runs once after success, action failure, mismatch, or cancellation. Failed preparation leaves partially acquired resources to the driver. Cleanup failure prevents success; an execution and cleanup failure are both retained in an ExceptionGroup (BaseExceptionGroup when cancellation is a base exception). Cancellation is cooperative through the optional cancelled callback. A matching observation after cancellation cannot pass, and cleanup still runs.

An optional event observer receives execution-local Given, When, Expect, application explanations, and valid Actual observations in order. Values are copied when delivered. Events do not affect comparison or pass status. Without an observer the SDK retains no event history and writes no output.

pytest is a consumer-owned development/test dependency. The SDK itself does not provide pytest discovery or a focused-spec plugin. The maintained bank example demonstrates the canonical scenarios shared by ordinary pytest tests and a readable demo.

Metadata

Release files for focused-spec-scenarios 0.10.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 focused-spec-scenarios 0.10.0
File Size Uploaded Provenance Actions
focused_spec_scenarios-0.10.0.tar.gz 6.5 kB Without provenance Details for focused_spec_scenarios-0.10.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for focused-spec-scenarios 0.10.0
File Interpreter ABI Platform Actions
focused_spec_scenarios-0.10.0-py3-none-any.whl Python 3 none any Details for focused_spec_scenarios-0.10.0-py3-none-any.whl

Total release size: 12.3 kB

Release files / focused_spec_scenarios-0.10.0.tar.gz

Download URL focused_spec_scenarios-0.10.0.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
dc75cdb19a90f1ae21acf613ef60690b62200266ef52cd7da6e5e53ca515704f
BLAKE2b-256 checksum
How to use checksums
95577d9c4649d54afea0ef6db30a55f0aae3b05291d0bbc7b8709109124f5e1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / focused_spec_scenarios-0.10.0-py3-none-any.whl

Download URL focused_spec_scenarios-0.10.0-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
45f48c3cd76ce6a5cc573da68061a2001637fe0e0c975cd21ccbcc6b43e9276d
BLAKE2b-256 checksum
How to use checksums
613469a99baaa4e684f5ad4fdd70ccc9d48939d471628209c3deb63c375073c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for focused-spec-scenarios 0.10.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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