Skip to content

Commit 7aa6604

Browse files
committed
docs: clarify .env requirement for running tests locally
Update documentation to explicitly state that a valid .env file is required to run tests locally. This was always needed for database access, but is now also enforced by credential validators.
1 parent c7ad151 commit 7aa6604

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

CONTRIBUTING.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,26 @@ ensure that the code is working as expected and will prevent any regressions.
196196
GitHub Actions will run the tests on every commit and PR, **failing tests will
197197
block the PR from being merged**, as will any major drop in test coverage.
198198

199+
### Prerequisites for Running Tests Locally
200+
201+
**IMPORTANT:** Before running tests locally, you **must** have a valid `.env` file configured with the following required settings:
202+
203+
- `SECRET_KEY` - Must be at least 32 characters long
204+
- `DB_USER` - Your PostgreSQL database username
205+
- `DB_PASSWORD` - Your PostgreSQL database password
206+
- `DB_ADDRESS` - Database host (usually `localhost`)
207+
- `DB_PORT` - Database port (usually `5432`)
208+
- `DB_NAME` - Your production database name
209+
- `TEST_DB_NAME` - Your test database name (defaults to `api-template-test`, **recommended to set explicitly**)
210+
211+
Tests will use the same database credentials (DB_USER/DB_PASSWORD) but connect to the TEST_DB_NAME database instead.
212+
213+
See the [Configuration](https://fastapi-template.seapagan.net/usage/configuration/setup/) section in the documentation for full setup instructions, or copy `.env.example` to `.env` and update the values.
214+
215+
Tests require these credentials to pass validation checks and connect to your local PostgreSQL database. **Tests will fail without a properly configured `.env` file.**
216+
217+
### Running Tests
218+
199219
There is a task set up to run tests:
200220

201221
```console

docs/development/local.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,23 @@ will automatically reload when it detects any changes as you develop.
4848
This API has **Unit** and **Integration** tests using
4949
'[Pytest](https://docs.pytest.org){:target="_blank"}'
5050

51-
!!! danger "Database Setup"
51+
!!! danger "Database and Environment Setup"
5252

53-
The tests will run using Posgresql against the database specified in the
54-
`TEST_DATABASE_URL` environment variable. This should be a test database,
55-
and will be cleared before each test run. **Do not use a production database
56-
for testing.**
53+
**Before running tests, you MUST have a valid `.env` file** with the following required settings:
5754

58-
You will also need to set up your environment file with the correct
59-
`DB_USER`, `DB_PASSWORD`, `DB_ADDRESS`, `DB_PORT` and `DB_NAME` values.
55+
- `SECRET_KEY` - Must be at least 32 characters long
56+
- `DB_USER` - Your PostgreSQL database username
57+
- `DB_PASSWORD` - Your PostgreSQL database password
58+
- `DB_ADDRESS` - Database host (usually `localhost`)
59+
- `DB_PORT` - Database port (usually `5432`)
60+
- `DB_NAME` - Your production database name
61+
- `TEST_DB_NAME` - Your test database name (defaults to `api-template-test`, **recommended to set explicitly**)
6062

61-
Tests run on GitHub Actions will ignore these settings and use their own
62-
hosted Postregsql test database.
63+
Tests will use the same database credentials (DB_USER/DB_PASSWORD) but connect to the TEST_DB_NAME database instead. **Do not use a production database for testing** as the test database will be cleared before each test run.
64+
65+
Copy `.env.example` to `.env` and update with your local values. See the [Configuration](/usage/configuration/setup/) section for full setup instructions.
66+
67+
Tests run on GitHub Actions use environment variables set in the CI workflow and a hosted PostgreSQL test database.
6368

6469
To run these from within the virtual environment use the `pytest` command:
6570

0 commit comments

Comments
 (0)