@@ -258,7 +258,7 @@ docker compose -f docker-compose.test.yml up --build -d
258258** Step 5: Run integration tests**
259259``` bash
260260cd backend
261- DB_HOST=127.0.0.1 DB_PORT=5435 TEST_BASE_URL=http://localhost:8001 poetry run pytest -m integration --use-local-db --run-all
261+ DB_HOST=127.0.0.1 DB_PORT=5435 TEST_BASE_URL=http://localhost:8001 DJANGO_SETTINGS_MODULE=kernelCI.test_settings poetry run pytest -m integration --use-local-db --run-all
262262```
263263
264264** Step 6: Clean up**
@@ -278,30 +278,42 @@ The test environment uses `backend/kernelCI/test_settings.py` which:
278278Most integration tests are HTTP black-box tests against the running ` test_backend `
279279container, but some (e.g. management-command tests) are DB-backed and use
280280` @pytest.mark.django_db ` with factories. Those connect to PostgreSQL directly from
281- the host, so the run commands set ` DB_HOST=127.0.0.1 DB_PORT=5435 ` to reach the
282- ` test_db ` container (published on port ` 5435 ` ); ` pytest-django ` then creates its own
283- isolated ` test_* ` database, separate from the seeded one used by the HTTP tests.
281+ the host, so the run commands set ` DB_HOST=127.0.0.1 ` and ` DB_PORT=5435 ` to reach the
282+ ` test_db ` container (published on port ` 5435 ` ) instead of the in-network ` test_db:5432 `
283+ default. The name/user/password come from ` test_settings ` defaults (` kcidb_test ` /
284+ ` test_user ` /` test_password ` ), so they don't need to be passed. ` pytest-django ` then
285+ creates its own isolated ` test_* ` database, separate from the seeded one used by the
286+ HTTP tests.
287+
288+ The commands also set ` DJANGO_SETTINGS_MODULE=kernelCI.test_settings ` explicitly. The
289+ ` --use-local-db ` flag alone is not enough: ` pytest-django ` reads the ` DJANGO_SETTINGS_MODULE `
290+ ini option from ` pyproject.toml ` (` kernelCI.settings ` ) and configures Django before
291+ ` conftest.py ` can switch it. Under ` kernelCI.settings ` the ` cache ` /` notifications ` DBs are
292+ file-based sqlite under ` /volume_data ` , which does not exist on the CI runner; the parallel
293+ (` -n 4 ` ) test-DB setup then fails with "unable to open database file". ` test_settings ` uses
294+ in-memory sqlite instead, and the env var wins over the ini, so it forces the correct
295+ settings.
284296
285297### Running Specific Tests
286298
287299** Run all integration tests:**
288300``` bash
289- DB_HOST=127.0.0.1 DB_PORT=5435 TEST_BASE_URL=http://localhost:8001 poetry run pytest -m integration --use-local-db --run-all
301+ DB_HOST=127.0.0.1 DB_PORT=5435 TEST_BASE_URL=http://localhost:8001 DJANGO_SETTINGS_MODULE=kernelCI.test_settings poetry run pytest -m integration --use-local-db --run-all
290302```
291303
292304** Run only a subset of tests (faster):**
293305``` bash
294- DB_HOST=127.0.0.1 DB_PORT=5435 TEST_BASE_URL=http://localhost:8001 poetry run pytest -m integration --use-local-db
306+ DB_HOST=127.0.0.1 DB_PORT=5435 TEST_BASE_URL=http://localhost:8001 DJANGO_SETTINGS_MODULE=kernelCI.test_settings poetry run pytest -m integration --use-local-db
295307```
296308
297309** Run specific test file:**
298310``` bash
299- DB_HOST=127.0.0.1 DB_PORT=5435 TEST_BASE_URL=http://localhost:8001 poetry run pytest -m integration --use-local-db backend/kernelCI_app/tests/integrationTests/< your_test> .py
311+ DB_HOST=127.0.0.1 DB_PORT=5435 TEST_BASE_URL=http://localhost:8001 DJANGO_SETTINGS_MODULE=kernelCI.test_settings poetry run pytest -m integration --use-local-db backend/kernelCI_app/tests/integrationTests/< your_test> .py
300312```
301313
302314** Run specific method:**
303315``` bash
304- DB_HOST=127.0.0.1 DB_PORT=5435 TEST_BASE_URL=http://localhost:8001 poetry run pytest -m integration --use-local-db backend/kernelCI_app/tests/integrationTests/< your_test> .py::< your_function>
316+ DB_HOST=127.0.0.1 DB_PORT=5435 TEST_BASE_URL=http://localhost:8001 DJANGO_SETTINGS_MODULE=kernelCI.test_settings poetry run pytest -m integration --use-local-db backend/kernelCI_app/tests/integrationTests/< your_test> .py::< your_function>
305317```
306318
307319### Troubleshooting
0 commit comments