Skip to content

Commit 3e6bc74

Browse files
committed
fix: Add DB env to integration
Signed-off-by: Alan Peixinho <alan.peixinho@profusion.mobi>
1 parent 1042047 commit 3e6bc74

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ jobs:
164164
165165
- name: Run integration tests with coverage
166166
run: |
167-
TEST_BASE_URL=http://localhost:8001 poetry run pytest -m "integration" --use-local-db --run-all --cov=kernelCI_app --cov=kernelCI_cache --cov-report=term-missing
167+
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 --cov=kernelCI_app --cov=kernelCI_cache --cov-report=term-missing
168168
cp .coverage coverage-integration.sqlite
169169
working-directory: ./backend
170170

docs/IntegrationTests.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ docker compose -f docker-compose.test.yml up --build -d
258258
**Step 5: Run integration tests**
259259
```bash
260260
cd backend
261-
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 poetry run pytest -m integration --use-local-db --run-all
262262
```
263263

264264
**Step 6: Clean up**
@@ -275,26 +275,33 @@ The test environment uses `backend/kernelCI/test_settings.py` which:
275275
- Configures local PostgreSQL database
276276
- Sets `TEST_BASE_URL=http://localhost:8001/`
277277

278+
Most integration tests are HTTP black-box tests against the running `test_backend`
279+
container, but some (e.g. management-command tests) are DB-backed and use
280+
`@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.
284+
278285
### Running Specific Tests
279286

280287
**Run all integration tests:**
281288
```bash
282-
TEST_BASE_URL=http://localhost:8001 poetry run pytest -m integration --use-local-db --run-all
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
283290
```
284291

285292
**Run only a subset of tests (faster):**
286293
```bash
287-
TEST_BASE_URL=http://localhost:8001 poetry run pytest -m integration --use-local-db
294+
DB_HOST=127.0.0.1 DB_PORT=5435 TEST_BASE_URL=http://localhost:8001 poetry run pytest -m integration --use-local-db
288295
```
289296

290297
**Run specific test file:**
291298
```bash
292-
TEST_BASE_URL=http://localhost:8001 poetry run pytest -m integration --use-local-db backend/kernelCI_app/tests/integrationTests/<your_test>.py
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
293300
```
294301

295302
**Run specific method:**
296303
```bash
297-
TEST_BASE_URL=http://localhost:8001 poetry run pytest -m integration --use-local-db backend/kernelCI_app/tests/integrationTests/<your_test>.py::<your_function>
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>
298305
```
299306

300307
### Troubleshooting

0 commit comments

Comments
 (0)