@@ -123,6 +123,22 @@ netbox-test() {
123123 cd /opt/netbox/netbox && source /opt/netbox/venv/bin/activate && python manage.py test netbox_interface_name_rules " $@ "
124124}
125125
126+ # Run tests on a per-session ISOLATED test database, so concurrent suites in the
127+ # shared devcontainer don't collide on test_netbox (which corrupts migrations and
128+ # can leave lock-holding zombie connections). Pass the app(s) + any test flags,
129+ # e.g. netbox-test-isolated netbox_nso_plugin --keepdb
130+ # Override the DB name with TEST_DB_NAME=...; otherwise it's derived from the first
131+ # app argument (a stable name so --keepdb can reuse it).
132+ netbox-test-isolated () {
133+ local first_app=" netbox_interface_name_rules"
134+ case " ${1:- } " in -* |" " ) ;; * ) first_app=" $1 " ;; esac
135+ local db_name=" ${TEST_DB_NAME:- test_$(printf ' %s' " $first_app " | tr -c ' a-zA-Z0-9' ' _' )} "
136+ cd /opt/netbox/netbox && source /opt/netbox/venv/bin/activate && \
137+ PYTHONPATH=" $PLUGIN_DIR /.devcontainer/config${PYTHONPATH: +: $PYTHONPATH } " \
138+ TEST_DB_NAME=" $db_name " \
139+ python manage.py test " $@ " --settings=isolated_test_settings
140+ }
141+
126142netbox-manage () {
127143 cd /opt/netbox/netbox && source /opt/netbox/venv/bin/activate && python manage.py " $@ "
128144}
@@ -199,6 +215,7 @@ dev-help() {
199215 echo " 🛠️ Development Tools:"
200216 echo " netbox-shell : Open NetBox Django shell"
201217 echo " netbox-test : Run plugin tests"
218+ echo " netbox-test-isolated: Run tests on a per-session isolated test DB (concurrency-safe)"
202219 echo " netbox-manage : Run Django management commands"
203220 echo " plugin-install : Reinstall plugin in development mode"
204221 echo " "
0 commit comments