From 30f6d6c8c1d6164ed0e789bc1f0ed65f8d9ec5d2 Mon Sep 17 00:00:00 2001 From: bronsen Date: Thu, 13 Mar 2025 17:15:23 +0100 Subject: [PATCH] [config] load testing env when under pytest --- .env.test | 4 ++++ config/settings.py | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .env.test diff --git a/.env.test b/.env.test new file mode 100644 index 0000000..e987881 --- /dev/null +++ b/.env.test @@ -0,0 +1,4 @@ +DATABASE_URL=psql://teilchensammler:teilchensammler@localhost:5432/teilchensammler_test +DEBUG=On +SECRET_KEY=django-insecure-x=%#_wxu0h=d*m#seui9+mjh3vu7of8+4+gpwj@556.un0r1%. +DEV=On diff --git a/config/settings.py b/config/settings.py index 1b34947..1ba5c58 100644 --- a/config/settings.py +++ b/config/settings.py @@ -10,13 +10,18 @@ https://docs.djangoproject.com/en/5.1/ref/settings/ import environ from pathlib import Path +import sys BASE_DIR = Path(__file__).resolve().parent.parent + env = environ.Env( DEBUG=(bool, False), DEV=(bool, False), ) -environ.Env.read_env(BASE_DIR / ".env") +if "pytest/__main__.py" in sys.argv[0]: + env.read_env(BASE_DIR / ".env.test") +else: + env.read_env(BASE_DIR / ".env") # See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/