Run the plugin's test suite
This plugin uses Django's built-in test runner (django.test.TestCase), not pytest — pyproject.toml lists pytest as a test extra but the suite is invoked via NetBox's manage.py test. CI runs this exact command in .github/workflows/lint-tests.yaml.
Canonical command
From the NetBox repo root (with the plugin installed in editable mode and testing/configuration.py linked into NetBox):
python netbox/manage.py test netbox_branching.tests --keepdb
This is the same command CI runs. Add -v 2 to print each test as it executes; drop to -v 1 for terser output.
Prerequisites (one-time setup)
- NetBox checkout alongside this repo (
../netboxor any sibling path). testing/configuration.pysymlinked into NetBox:
This config setsln -sf "$PWD/testing/configuration.py" ../netbox/netbox/netbox/configuration.pyPLUGINS = ['netbox_branching'], wrapsDATABASESwithDynamicSchemaDict, addsBranchAwareRoutertoDATABASE_ROUTERS, and points at a local Postgres + Redis on default ports (netbox/netbox/netbox).- Plugin installed in editable mode with test extras:
pip install -e '.[dev,test]' - NetBox dependencies installed:
pip install -r ../netbox/requirements.txt. - Postgres + Redis reachable on localhost (defaults).
If any of these are missing, surface the gap to the user — do not silently skip.
Useful variants
Run a single test module / class / method (Django's dotted-path target):
python netbox/manage.py test netbox_branching.tests.test_branches --keepdb
python netbox/manage.py test netbox_branching.tests.test_api --keepdb
python netbox/manage.py test netbox_branching.tests.test_iterative_merge.IterativeMergeTestCase --keepdb
Available test modules in netbox_branching/tests/:
test_api— REST API endpoints (CRUD, sync/merge/revert/migrate actions).test_branches— Branch model operations and lifecycle.test_changediff—ChangeDiffconflict detection.test_config— Plugin configuration validation.test_connection_lifecycle— Database connection management.test_events—BranchEventcreation.test_filtersets— Filterset behaviour (FK_idfilters, etc.).test_iterative_merge— Iterative merge strategy (comprehensive).test_query— Branch-aware query routing.test_related_models— Related model handling across schemas.test_request— Request-level branch context.test_squash_merge— Squash merge strategy (comprehensive).test_sync— Branch sync operations (comprehensive).test_views— UI views via NetBox's test client.
Stop on first failure: --failfast. Run in parallel: --parallel auto (note: --keepdb and --parallel don't always compose cleanly).
After model changes
Generate migrations before running tests, otherwise the test DB build will fail:
python netbox/manage.py makemigrations netbox_branching
Why these choices
- Don't substitute pytest. The suite uses
django.test.TestCase; pytest would needpytest-djangoconfigured against NetBox's settings, which nobody has set up. Run viamanage.py testto match CI. - Always use
--keepdb. Branch schema provisioning and teardown hit a real PostgreSQL database. Recreating the test DB on every run is slow and unnecessary;--keepdbpreserves it between runs. - Don't mock the database. Tests exercise the real ORM, views, and APIs end-to-end. The whole point of this plugin is schema-level database isolation — a mocked DB can't exercise that.
- Match CI's invocation. If a test passes locally but fails in CI, the first diagnostic is "did you run the same command?" — keeping the canonical form identical removes that variable.
References
AGENTS.md"Testing" and "Development" sections — environment setup and layout..github/workflows/lint-tests.yaml— authoritative CI invocation.testing/configuration.py— NetBox config the test runner uses.