Skip to content
SequencyLabsPublic

About

Mutation testing for Python, psycopg SQL strings, and PostgreSQL views and functions.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

pgmutate

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.

Install

pip install pgmutate

Requires Python 3.12 or newer. pgmutate pins mutmut==3.8.1.

Usage

pgmutate generate out --config pgmutate.toml
pgmutate run out --config pgmutate.toml --shards 4
pgmutate report out --config pgmutate.toml

Or pass targets on the command line:

pgmutate generate out --package app=src --sql-glob "sql/*.sql"
pgmutate run out --shards 4 tests/
pgmutate report out
  • generate writes mutated Python code into out/py and all mutant definitions into out/mutants.json.
  • run executes parallel pytest shards with -p pgmutate.plugin. Each shard records reached functions, psycopg queries, and PostgreSQL tables, then runs each reached mutant. Dead or silent shards restart and skip completed runs.
  • report writes out/matrix.csv, out/survivors.json, and out/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.

Configuration

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"

PostgreSQL fixtures

To mutate sql_globs definitions, your test suite must provide three pytest fixtures (names configurable above):

  • url_fixture (default postgres): session-scoped fixture returning a PostgreSQL connection URL string.
  • template_fixture (default migrated_template): session-scoped fixture returning the name of the migrated template database.
  • db_fixture (default scratch_db): function-scoped fixture returning a scratch database URL cloned from that template.

Limits

  • Requires POSIX (SIGALRM, os.killpg) and synchronous psycopg.Cursor (AsyncCursor is not wrapped).
  • SQL mutations do not remove locks or FOR UPDATE clauses.
  • Dynamic SQL strings (f-strings, %, .format) receive no pysql mutants.
  • PostgreSQL SQLSTATE class 42 errors mark a pysql mutant invalid. Class 22 errors count as kills.

License

Dual-licensed under MIT and Apache-2.0.

About

Mutation testing for Python, psycopg SQL strings, and PostgreSQL views and functions.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages