-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_environment_vars.py
26 lines (23 loc) · 1.1 KB
/
set_environment_vars.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
from dotenv import load_dotenv, find_dotenv
def set_environment_vars():
"""Set the env vars to have values for testing,
in particular for the test database
"""
ENV_FILE = find_dotenv()
if ENV_FILE:
load_dotenv(ENV_FILE)
# Note that this testing apparently runs in its own environment,
# so there is no need to save and restore env variables.
try:
os.environ['ESPRESSO_DB_USER'] = os.environ['ESPRESSO_TEST_DB_USER']
os.environ['ESPRESSO_DB_PASSWORD'] = os.environ['ESPRESSO_TEST_DB_PASSWORD']
os.environ['ESPRESSO_DB_HOST'] = os.environ['ESPRESSO_TEST_DB_HOST']
os.environ['ESPRESSO_DB_DATABASE_NAME'] = os.environ['ESPRESSO_TEST_DB_DATABASE_NAME']
except KeyError as ex:
print("\nTesting requires these environment variables: " \
"ESPRESSO_TEST_DB_USER ESPRESSO_TEST_DB_PASSWORD "
"ESPRESSO_TEST_DB_HOST ESPRESSO_TEST_DB_DATABASE_NAME")
print(f"Environment variable {ex.args[0]} is missing")
print(f"Please set {ex.args[0]}, check the others, and retry the testing\n")
raise