Skip to main content

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 SchemaConfig you 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_misata-0.1.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_misata-0.1.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

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

Hashes for pytest_misata-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1da790e944811c755376c3430c93f62e3bd8ea6b59732a3d5565b3421ddc4476
MD5 c1eb2baed3cd2e270c66af2f87a4eeff
BLAKE2b-256 68c25e789506ba217fec01dd367443fc901542e808c340ff713f8ed0ce7cc335

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_misata-0.1.0.tar.gz:

Publisher: publish.yml on rasinmuhammed/pytest-misata

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for pytest_misata-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 913b5eee4b80732e45456bc17b247ccb6f9b8c7262dd8890937f595365ac3180
MD5 765a29ea19782088df014ef4a1d525c8
BLAKE2b-256 9241e651b28d84fbbd97a3f16499412a75009b44241bd79cd5692ad5fc33466a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_misata-0.1.0-py3-none-any.whl:

Publisher: publish.yml on rasinmuhammed/pytest-misata

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page