Skip to content

Stop tests reading the developer's personal env file - #66

Merged
gosku merged 1 commit into
mainfrom
isolate-tests-from-personal-env
Jul 27, 2026
Merged

Stop tests reading the developer's personal env file#66
gosku merged 1 commit into
mainfrom
isolate-tests-from-personal-env

Conversation

@gosku

@gosku gosku commented Jul 27, 2026

Copy link
Copy Markdown
Owner

settings.py loaded src/config/env unconditionally, and pytest.ini points at that same settings module, so the suite ran on whatever the local machine happened to be configured for. The file is gitignored, so CI has none and always runs on the declared defaults. Any locally tuned setting therefore changed what the tests asserted against, failing on one machine while passing in CI. A local IMAGE_MAX_RATING of 2 was breaking four set_images_rating tests this way.

load_dotenv now reads whatever FILMCASE_ENV_FILE points at, defaulting to the personal file so runtime behaviour is unchanged. A pytest plugin aims it at os.devnull, an empty file by definition, so every setting falls back to its default. Real environment variables still win over the file, so a contributor whose database differs from the defaults can still use DB_PORT=5433 pytest.

This has to be a -p plugin rather than a conftest.py hook. pytest-django sets Django up in pytest_load_initial_conftests, the same hook that loads the root conftest, and it wins that race, so by then the settings module is already imported and the env file already read. Plugins named with -p are imported during preparse, which is early enough.

settings.py loaded src/config/env unconditionally, and pytest.ini points at that
same settings module, so the suite ran on whatever the local machine happened to
be configured for. The file is gitignored, so CI has none and always runs on the
declared defaults. Any locally tuned setting therefore changed what the tests
asserted against, failing on one machine while passing in CI. A local
IMAGE_MAX_RATING of 2 was breaking four set_images_rating tests this way.

load_dotenv now reads whatever FILMCASE_ENV_FILE points at, defaulting to the
personal file so runtime behaviour is unchanged. A pytest plugin aims it at
os.devnull, an empty file by definition, so every setting falls back to its
default. Real environment variables still win over the file, so a contributor
whose database differs from the defaults can still use DB_PORT=5433 pytest.

This has to be a -p plugin rather than a conftest.py hook. pytest-django sets
Django up in pytest_load_initial_conftests, the same hook that loads the root
conftest, and it wins that race, so by then the settings module is already
imported and the env file already read. Plugins named with -p are imported
during preparse, which is early enough.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@gosku
gosku merged commit 2385879 into main Jul 27, 2026
4 checks passed
@gosku
gosku deleted the isolate-tests-from-personal-env branch July 27, 2026 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant