This repository is a read-only mirror from our internal codebase. We monitor issues, but we do not accept pull requests here.
pgmutate runs mutation tests on Python functions (via mutmut), SQL strings passed to psycopg, and PostgreSQL views and functions.
pip install pgmutateRequires Python 3.12 or newer. pgmutate pins mutmut==3.8.1.
pgmutate generate out --config pgmutate.toml
pgmutate run out --config pgmutate.toml --shards 4
pgmutate report out --config pgmutate.tomlOr pass targets on the command line:
pgmutate generate out --package app=src --sql-glob "sql/*.sql"
pgmutate run out --shards 4 tests/
pgmutate report outgeneratewrites mutated Python code intoout/pyand all mutant definitions intoout/mutants.json.runexecutes parallelpytestshards with-p pgmutate.plugin. Each shard records reached functions,psycopgqueries, and PostgreSQL tables, then runs each reached mutant. Dead or silent shards restart and skip completed runs.reportwritesout/matrix.csv,out/survivors.json, andout/redundant.json, then prints totals and redundant tests.
Filter mutants with comma-separated ID prefixes:
pgmutate run out --config pgmutate.toml --only db.,app.billing. tests/test_billing.py
pgmutate report out --config pgmutate.toml --only db.,app.billing.root = "."
sql_package = "db"
sql_globs = ["db/views/*.sql", "db/functions/*.sql"]
sql_schemas = ["public"]
keep_file = "keep.txt"
tests = ["tests/"]
last_patterns = ["tests/e2e/"]
readonly_globs = ["**/snapshots/*.json"]
url_fixture = "postgres"
template_fixture = "migrated_template"
db_fixture = "scratch_db"
watchdog_seconds = 900
[packages]
app = "src"To mutate sql_globs definitions, your test suite must provide three pytest fixtures (names configurable above):
url_fixture(defaultpostgres): session-scoped fixture returning a PostgreSQL connection URL string.template_fixture(defaultmigrated_template): session-scoped fixture returning the name of the migrated template database.db_fixture(defaultscratch_db): function-scoped fixture returning a scratch database URL cloned from that template.
- Requires POSIX (
SIGALRM,os.killpg) and synchronouspsycopg.Cursor(AsyncCursoris not wrapped). - SQL mutations do not remove locks or
FOR UPDATEclauses. - Dynamic SQL strings (f-strings,
%,.format) receive nopysqlmutants. - PostgreSQL SQLSTATE class 42 errors mark a
pysqlmutant invalid. Class 22 errors count as kills.
Dual-licensed under MIT and Apache-2.0.