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.2
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 |
|---|---|---|---|---|
| focused_spec_scenarios-0.10.2.tar.gz | 6.5 kB | Without provenance | Details for focused_spec_scenarios-0.10.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| focused_spec_scenarios-0.10.2-py3-none-any.whl | Python 3 | none | any | Details for focused_spec_scenarios-0.10.2-py3-none-any.whl |
Total release size: 12.3 kB
Release files / focused_spec_scenarios-0.10.2.tar.gz
| Download URL | focused_spec_scenarios-0.10.2.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2883d0699bb0fb52bae0cf986ba082383f306f815634e64dc1f8cff4f6684744
|
|
BLAKE2b-256 checksum How to use checksums |
862d7dfdaa8956c94e75fa9d17fa380f643c563f722d2964a447fd3fcd26e016
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.15
|
Release files / focused_spec_scenarios-0.10.2-py3-none-any.whl
| Download URL | focused_spec_scenarios-0.10.2-py3-none-any.whl |
|---|---|
| Size | 5.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
312d0c523e1204853457713891a9ebb668b9aca4c0777e0b0a0bbc21e8b0c094
|
|
BLAKE2b-256 checksum How to use checksums |
5f3b6d097380320a752c4611fa6fe22cef3ea7b5443ade28e06dda4df1e4e955
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.15
|
Security for focused-spec-scenarios 0.10.2
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.