From 673b6e6abfcef4216e28768ba2e900e565f5ddc6 Mon Sep 17 00:00:00 2001 From: Andrew Liu Date: Tue, 16 Apr 2024 19:18:48 +0000 Subject: [PATCH] dependency injection --- server_tests/conftest.py | 41 +++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/server_tests/conftest.py b/server_tests/conftest.py index 5e598bfa1..84f9f67a1 100644 --- a/server_tests/conftest.py +++ b/server_tests/conftest.py @@ -63,25 +63,6 @@ def redis_host(): yield host -@pytest.fixture(scope="session") -def app(db_url: str, redis_host: str): - os.environ["DATABASE_URL"] = db_url - os.environ["REDIS_HOST"] = redis_host - - app = create_app() - app.config.update( - { - "TESTING": True, - } - ) - - with app.app_context(): - from server_tests.utils import seed_database - seed_database() - - yield app - - @pytest.fixture(autouse=True) def mock_openai_chat_completion(): """Mock the OpenAI chat completion API.""" @@ -127,6 +108,28 @@ def mock_openai_embeddings(): yield mock +@pytest.fixture(scope="session") +def app( + db_url: str, redis_host: str, mock_openai_chat_completion, mock_openai_embeddings +): + os.environ["DATABASE_URL"] = db_url + os.environ["REDIS_HOST"] = redis_host + + app = create_app() + app.config.update( + { + "TESTING": True, + } + ) + + with app.app_context(): + from server_tests.utils import seed_database + + seed_database() + + yield app + + @pytest.fixture(autouse=True) def enable_transactional_tests(app: APIFlask): """Enables fast independent tests by rolling back changes made during every test.