Working with async databases

Run your FastAPI tests in 'test' mode

Want more?

This lesson for enrolled students only. Join the course to unlock it!

You can see the code changes implemented in this lecture below.

If you have purchased the course in a different platform, you still have access to the code changes per lecture here on Teclado. The lecture video and lecture notes remain locked.
Join course for $30

Modified files

storeapi/main.py
--- 
+++ 
@@ -13,4 +13,3 @@

 app = FastAPI(lifespan=lifespan)
 app.include_router(posts_router)
-
storeapi/tests/conftest.py
--- 
+++ 
@@ -1,10 +1,13 @@
+import os
 from typing import AsyncGenerator, Generator

 import pytest
 from fastapi.testclient import TestClient
 from httpx import AsyncClient
-from storeapi.main import app
 from storeapi.routers.posts import comments_table, post_table
+
+os.environ["ENV_STATE"] = "test"
+from storeapi.main import app  # noqa: E402


 @pytest.fixture(scope="session")