Skip to content

Commit

Permalink
add local env to fix test discrepancies
Browse files Browse the repository at this point in the history
  • Loading branch information
azliu0 committed Apr 15, 2024
1 parent 1a6b163 commit 1ec95a9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 10 additions & 0 deletions server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
RedisDocument = dict[str, str]

ENV = os.environ.get("ENV", "development")
LOCAL = os.environ.get("LOCAL", "false")

if LOCAL != "true":
print("\033[91mWarning! you are missing the LOCAL environment variable.")
print("This will cause issues when running tests locally.")
print("""This is only acceptable in environments outside of development,
e.g., running tests with github actions.""")
print("Make sure you know what you are doing!\033[0m")
else:
print("\033[92mLocal environment detected.\033[0m")


def _get_config_option(name: str, default_value: str | None = None) -> str:
Expand Down
9 changes: 6 additions & 3 deletions server_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from sqlalchemy.engine.base import Connection

from server import create_app, db
from server.config import LOCAL


@pytest.fixture(scope="session")
Expand All @@ -20,11 +21,12 @@ def db_url(db_name="pigeondb_test"):
Drops and recreates the database if it already exists.
"""
host = "database" if LOCAL else "localhost"
conn = psycopg2.connect(
dbname="postgres",
user="postgres",
password="password",
host="database",
host=host,
port="5432",
)
conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
Expand All @@ -47,11 +49,12 @@ def redis_db_index():
Flushes test db if it already exists.
"""
client = redis.Redis(host="redis-test", port=6379)
host = "redis-test" if LOCAL else "localhost"
client = redis.Redis(host=host, port=6379)
client.flushdb()
client.close()

yield "redis-test"
yield host


@pytest.fixture(scope="session")
Expand Down

0 comments on commit 1ec95a9

Please sign in to comment.