diff --git a/README.md b/README.md index c4b2270..4037a7d 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ well with fish shell. Have Python >= 3.12 installed. I use [pyenv] (which in turn is installed by [homebrew]). Set up Postgresql, a role and a schema. I have it on localhost, using the -project name for role and schema name, and password. See `.env.sample` for +project name for role and schema name, and password. See `.env.test` for providing connection information. Clone the repo. `cd` into the project directory. ([direnv] should activate the diff --git a/config/settings.py b/config/settings.py index 5d377c0..bde6d3d 100644 --- a/config/settings.py +++ b/config/settings.py @@ -10,7 +10,6 @@ https://docs.djangoproject.com/en/5.1/ref/settings/ import environ from pathlib import Path -import sys BASE_DIR = Path(__file__).resolve().parent.parent @@ -18,10 +17,7 @@ env = environ.Env( DEBUG=(bool, False), DEPLOYMENT=(str, "Dev"), ) -if "pytest/__main__.py" in sys.argv[0]: - env.read_env(BASE_DIR / ".env.test") -else: - env.read_env(BASE_DIR / ".env") +env.read_env(env.str("ENV_PATH", BASE_DIR / ".env")) # pyright: ignore[reportArgumentType] # See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/ @@ -44,12 +40,10 @@ INSTALLED_APPS = [ "collector.apps.CollectorConfig", ] if env("DEPLOYMENT") == "Dev": - INSTALLED_APPS.extend( - [ - "django_extensions", - "debug_toolbar", - ] - ) + INSTALLED_APPS += [ + "django_extensions", + "debug_toolbar", + ] SHELL_PLUS = "ipython" MIDDLEWARE = [ @@ -62,7 +56,9 @@ MIDDLEWARE = [ "django.middleware.clickjacking.XFrameOptionsMiddleware", ] if env("DEPLOYMENT") == "Dev": - MIDDLEWARE.append("debug_toolbar.middleware.DebugToolbarMiddleware") + MIDDLEWARE += [ + "debug_toolbar.middleware.DebugToolbarMiddleware", + ] INTERNAL_IPS = [ "127.0.0.1", ] diff --git a/config/test.py b/config/test.py new file mode 100644 index 0000000..845afc3 --- /dev/null +++ b/config/test.py @@ -0,0 +1,5 @@ +import os + + +def test_we_are_using_the_correct_envpath(): + assert os.environ.get("ENV_PATH", "") == ".env.test" diff --git a/justfile b/justfile index 9f998f9..5a54d88 100644 --- a/justfile +++ b/justfile @@ -16,4 +16,4 @@ serve: python -m django runserver test *ARGS: - python -m pytest {{ARGS}} + ENV_PATH=.env.test python -m pytest {{ARGS}} diff --git a/pyproject.toml b/pyproject.toml index 80cba80..14b76a0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,8 @@ authors = [ pythonpath = "." python_files = [ "test_*.py", - "tests.py" + "tests.py", + "config/test.py", ] addopts = [ "--create-db",