Tutorial · target: how to make api tests deterministic

How to Generate Event stream fixture for a determinism walkthrough Seed Data with One Command

User has flaky tests caused by random data and wants them stabilised.

Direct answer

Generating a seed and a negative fixture set for Event stream fixture for a determinism walkthrough takes one generate command and produces a set of committed files, with no hand-written INSERT statement in between.

The steps assume Node.js 22.6 or newer and the schema document that ships with this page; a schema with remote $ref URLs needs the files downloaded first.

One generate command writes 2 tables in dependency order into ./seed/sql/seed.sql, and the negative cases go to ./seed/sql/negatives.sql beside it; the same run also writes the pytest suite in ./seed/pytest, where each negative case is asserted against the schema keyword it breaks.

Data as of 2026-11-18 · source: 10 Stack Overflow questions, 21 Hacker News stories, hashery at 166,440,359 monthly downloads · negative-case messages reproduced by executing the fixture against a local SQL engine (Node.js v24.22.0, engine 3.53.4) at 2026-11-18T11:53:54.233Z

Prerequisites — Event stream

You need a schema document for Event stream fixture for a determinism walkthrough and a Node.js runtime. The Event stream fixture for a determinism walkthrough fixture used here has 2 tables, and the commands below assume the file is at openapi/file that ships with this page. Nothing else is required: no database connection, no API key, no network access at generation time.

The steps

One command does the work. The generate command reads the schema, writes the seed and the negative cases in a single pass, and prints what it produced: the tables it wrote, the rows per table and the number of negative cases. For Event stream fixture for a determinism walkthrough that is 2 tables in dependency order, with 13 constraints carried into the DDL. Two read-only commands sit next to it for checking instead of writing: validate reports the $ref chains that cannot be resolved and exits non-zero when one is broken, and inspect prints the tables, columns, primary keys and foreign keys the tool derived.

What you end up with

A set of committed artefacts: the PostgreSQL seed script, the negative SQL cases and the pytest suite. The seed for Event stream fixture for a determinism walkthrough contains 2 table definitions and their rows in dependency order. The negative file holds the instances the API must reject, one per constraint class that the fixture declares, and the pytest suite carries both the valid rows and the negative ones. All of them are text, all of them diff in review, and all of them are regenerated by re-running the same command.

Wiring it into CI

The CI step is a diff, not a test. Regenerate the seed and fail the build if the committed file differs from the regenerated one. That single check catches the case where Event stream fixture for a determinism walkthrough changed shape and the fixture did not, which is the failure that a hand-maintained seed produces silently for months.

Troubleshooting

If the generator warns about a schema it skipped, the warning names the construct. For Event stream fixture for a determinism walkthrough, the constructs worth knowing about are the range declaration on events.seq and the reference from events to sessions. A skipped construct is reported, never silently dropped, which is the behaviour to insist on from any tool in this position.

Real constraint failures for the Event stream fixture for a determinism walkthrough fixtureReproduced by executing the fixture against a local SQL engine (Node.js v24.22.0, engine 3.53.4) on 2026-11-18T11:53:54.233Z. The message column is verbatim engine output; the SQLSTATE column is the PostgreSQL error class for the same constraint class.
Failure classColumnSQLSTATEError nameEngine message (verbatim)
Missing required fieldsessions.session_key23502not_null_violationNOT NULL constraint failed: sessions.session_key
Out-of-contract valueevents.seq23514check_violationCHECK constraint failed: events_seq_check
Dangling foreign keyevents.session_id23503foreign_key_violationFOREIGN KEY constraint failed
Insert order for Event stream fixture for a determinism walkthrough, derived from its foreign keysThe generator sorts the tables by this order before writing a single row.
TableReferenced byWritten
sessionseventsafter events
events—first, no dependencies
README.md

npx --yes @wenlu8848/schemaseed generate --input ./tut_events.openapi.yaml --out ./seed --formats pytest --count 10 --seed 42

Download tut_events.openapi.yaml

# Generated pytest suite

Seed: 42 — mode: nested

Run it with:

```
pytest pytest/
```

The suite is self contained: `_validator.py` implements the JSON Schema
keywords the generated data uses, so only pytest is needed.

- `test_sessions.py`: 10 valid rows, 15 negative cases (enum-violation, format-violation, missing-required, null-violation, type-mismatch)
- `test_events.py`: 10 valid rows, 24 negative cases (enum-violation, format-violation, missing-required, null-violation, range-violation, type-mismatch)

Frequently asked questions

How long does the whole workflow take?
One generate command and a moment on the Event stream fixture for a determinism walkthrough fixture of 2 tables; the slow part is deciding the row order, which is exactly what the generator removes.
What do I commit to the repository?
The generated files, all as text: the PostgreSQL seed script, the negative SQL cases and the pytest suite. Re-running with the same seed reproduces them byte for byte on the Event stream fixture for a determinism walkthrough schema.
Does the CI step need a database?
The drift check does not: it regenerates and fails if the committed file differs. Add a database service only if you also load the 2 tables.
What happens if my schema changes?
The regenerated file differs, CI fails with the diff attached, and every declaration in the schema is re-read, so a new one appears in the negative set immediately.

Run it against your own schema

SchemaSeed is MIT licensed and free: unlimited local generation, no account, no telemetry and no usage limit. It reads your schema file on your own machine, so nothing is uploaded anywhere. If it saves you time, you can support the project.

Get SchemaSeed — free Support the project

Questions: support@schemaseed.drz8848.win