Skip to main content
All failure patterns
Test data or state isolationpytest · Jest · CI

Unique constraint failed in a test

The test attempted to create a record whose unique value already exists in the database visible to that test.

RECOGNIZABLE ERROR

Unique constraint failed on the fields

RANKED DIAGNOSIS

What usually causes it

  1. 01

    Parallel tests share fixed fixture values

    Two workers create the same email, slug, key, or external id.

    DIAGNOSE

    Compare worker IDs and the colliding field across concurrent tests.

    FIX

    Generate a deterministic worker-scoped value and keep assertions independent of the literal.

  2. 02

    Cleanup did not run after an earlier failure

    A previous test left data that the next run assumes is absent.

    DIAGNOSE

    Query the record before setup and inspect teardown failures.

    FIX

    Use transaction rollback, isolated schemas, or idempotent setup and teardown.

  3. 03

    A retry repeats a non-idempotent setup

    The retried test creates the same record without resetting state.

    DIAGNOSE

    Check whether setup is inside the retried boundary.

    FIX

    Make setup idempotent or create fresh retry-scoped data.

Prevent the repeat

  • Give each worker isolated data.
  • Use transactional cleanup.
  • Make retry setup idempotent.

Primary references

Run this against your evidence

The browser triage workflow uses the same stable pattern slug and does not upload your paste.

Open local triage

Related failure patterns