pytest fixtures for Misata: deterministic, referentially-intact multi-table test data in one line
Project description
pytest-misata
pytest fixtures for Misata: deterministic, referentially-intact, multi-table test data in one line. No factories to maintain, no fixtures.json to hand-edit, no flaky random rows.
pip install pytest-misata
Five lines to seeded tests
def test_every_order_has_a_user(misata_tables):
tables = misata_tables({
"users": {"id": {"type": "integer", "primary_key": True},
"email": {"type": "email"}},
"orders": {"id": {"type": "integer", "primary_key": True},
"user_id": {"type": "integer",
"foreign_key": {"table": "users", "column": "id"}},
"amount": {"type": "float", "min": 5, "max": 500}},
}, seed=7, rows=200)
assert set(tables["orders"]["user_id"]) <= set(tables["users"]["id"])
The FK containment assertion above is not a hope: Misata guarantees it at generation time, for every relationship, every run.
The fixtures
misata_tables(spec, seed=42, rows=None)
Returns {table_name: DataFrame}. Accepts three spec forms:
- a dict schema (shown above),
- a
SchemaConfigyou built or loaded from YAML, - a plain-English story:
misata_tables("a SaaS with users and subscriptions", rows=500).
Session-scoped cache: fifty tests sharing one schema pay for one generation. Each call returns copies, so a test that mutates its frames cannot poison the next test.
misata_db(spec, seed=42, rows=None)
Same specs, but the tables land in a temporary SQLite database and you get the URL back:
from sqlalchemy import create_engine, text
def test_app_against_real_rows(misata_db):
db_url = misata_db(SCHEMA, seed=7, rows=500)
with create_engine(db_url).connect() as conn:
n = conn.execute(text("SELECT COUNT(*) FROM users")).scalar()
assert n == 500
Function-scoped: every test gets its own database file under pytest's tmp_path, so writes never leak between tests.
Why not factory_boy or hand-rolled fixtures?
Factories build one row at a time and know nothing about the rows around them, so the classic seed-data defects creep in: orders that ship before they are placed, totals that fail their own arithmetic, foreign keys pointing nowhere. Misata generates the whole relational story at once with those invariants enforced, then audits its own output before returning it. Run misata audit on your current seed directory if you want to see the difference measured.
Determinism contract
Same spec plus same seed produces the same bytes on every machine, every run, with no network and no API keys. Change the seed to rotate the whole dataset without touching a single assertion about declared properties.
License
MIT. The engine is misata, also MIT.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_misata-0.1.0.tar.gz.
File metadata
- Download URL: pytest_misata-0.1.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1da790e944811c755376c3430c93f62e3bd8ea6b59732a3d5565b3421ddc4476
|
|
| MD5 |
c1eb2baed3cd2e270c66af2f87a4eeff
|
|
| BLAKE2b-256 |
68c25e789506ba217fec01dd367443fc901542e808c340ff713f8ed0ce7cc335
|
Provenance
The following attestation bundles were made for pytest_misata-0.1.0.tar.gz:
Publisher:
publish.yml on rasinmuhammed/pytest-misata
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_misata-0.1.0.tar.gz -
Subject digest:
1da790e944811c755376c3430c93f62e3bd8ea6b59732a3d5565b3421ddc4476 - Sigstore transparency entry: 2173157817
- Sigstore integration time:
-
Permalink:
rasinmuhammed/pytest-misata@8a7bbfab3be54751154533647021b862a9c0a449 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/rasinmuhammed
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8a7bbfab3be54751154533647021b862a9c0a449 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pytest_misata-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pytest_misata-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
913b5eee4b80732e45456bc17b247ccb6f9b8c7262dd8890937f595365ac3180
|
|
| MD5 |
765a29ea19782088df014ef4a1d525c8
|
|
| BLAKE2b-256 |
9241e651b28d84fbbd97a3f16499412a75009b44241bd79cd5692ad5fc33466a
|
Provenance
The following attestation bundles were made for pytest_misata-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on rasinmuhammed/pytest-misata
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_misata-0.1.0-py3-none-any.whl -
Subject digest:
913b5eee4b80732e45456bc17b247ccb6f9b8c7262dd8890937f595365ac3180 - Sigstore transparency entry: 2173157831
- Sigstore integration time:
-
Permalink:
rasinmuhammed/pytest-misata@8a7bbfab3be54751154533647021b862a9c0a449 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/rasinmuhammed
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8a7bbfab3be54751154533647021b862a9c0a449 -
Trigger Event:
release
-
Statement type: