Skip to main content

django-baseshift-brancher

Run Django and pytest against a PostgreSQL database that is already migrated. Tests do not CREATE DATABASE and do not run migrations again.

This package applies migrations. Each new snapshot runs BASESHIFT_INIT_SQL before migrate when a migration needs an extension. Seed data and project management commands run on the clones afterwards.

This package does not include the baseshift program that creates those databases. Install that binary separately and put it on PATH. django-baseshift-brancher clone asks that program for one snapshot per git commit that changes migrations, reuses snapshots this checkout shares with other branches, and starts one Postgres per test worker. That program is not the PyPI project named baseshift.

pip install django-baseshift-brancher
# if pytest-django is not already installed:
pip install 'django-baseshift-brancher[pytest]'

Clone the current checkout

From the Django project directory:

export DJANGO_SETTINGS_MODULE=yourproject.settings
unset BASESHIFT_BRANCHES_FILE DATABASE_URL PGHOST PGPORT

django-baseshift-brancher clone --count 4

clone looks at git. Each commit that adds, removes, or replaces migration files is a snapshot. Adding files continues the previous snapshot, so two branches that diverged from the same migration commit share it. Replacing or removing a migration file starts again from the empty snapshot, because that schema cannot be applied on top of the previous one. A rebase writes a new commit, so that checkout gets a new snapshot on the new parent. A branch that left before the rebase keeps its own chain. You do not name snapshots or parents.

The command prints clone JSON and writes it to .brancher/clones.json. stderr prints the BASESHIFT_BRANCHES_FILE export. --count is the number of databases (one per pytest worker).

export BASESHIFT_BRANCHES_FILE="$PWD/.brancher/clones.json"
pytest -n 4
baseshift stop --all

clones.json is not picked up from the working directory. The BASESHIFT_BRANCHES_FILE export is what the tests read.

pytest needs no settings.py change. The plugin loads itself, points each worker at one clone, and forces --reuse-db and --no-migrations. Do not pass --create-db.

Django's runner needs one flag:

python manage.py test --testrunner django_baseshift_brancher.DiscoverRunner --parallel 4

--parallel 4 and pytest -n 4 both need four clones. pytest worker gw0 uses the first clone. Django's worker suffix is 1-based: "1" uses the first clone.

Existing DATABASES USER and PASSWORD are kept. HOST, PORT, and NAME are rewritten onto the clone, and migrations during tests are turned off.

export BASESHIFT_INIT_SQL="CREATE EXTENSION IF NOT EXISTS pg_trgm"   # when a migration needs it

That SQL runs on each new snapshot before migrate. After the clones are up, run project commands yourself — for example ensure_celery_broker_schema — against those DSNs.

Metadata

Release files for django-baseshift-brancher 0.12.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-baseshift-brancher 0.12.0
File Size Uploaded
django_baseshift_brancher-0.12.0.tar.gz 50.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-baseshift-brancher 0.12.0
File Interpreter ABI Platform
django_baseshift_brancher-0.12.0-py3-none-any.whl Python 3 none any Details

Total release size: 89.9 kB

Release files / django_baseshift_brancher-0.12.0.tar.gz

Download URL django_baseshift_brancher-0.12.0.tar.gz
Size 50.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3e2c9fc8f5cd128e1111a55fb67d9c7eabd9970e919752a236ff68ae2bf6ec68
BLAKE2b-256 checksum
How to use checksums
24d03989d7ffeb92b146ba8c1307eacb41c5c4456afae980a4f257e9f4915951
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / django_baseshift_brancher-0.12.0-py3-none-any.whl

Download URL django_baseshift_brancher-0.12.0-py3-none-any.whl
Size 39.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e04b2fe9b11815b5c1d8d9c9988e391c16378dd931db8801e89f9fa060052063
BLAKE2b-256 checksum
How to use checksums
661572378e68c46842cb158660e908ce497c5122e8dca2d476f781dd51a589f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

1.5.0

2 release files

1.4.0

2 release files

1.3.2

2 release files

0.13.0

2 release files

This release

0.12.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page