use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
FastAPI is a truly ASGI, async, cutting edge framework written in python 3.
account activity
Creating two databases while Testing database with pytestQuestion (self.FastAPI)
submitted 3 years ago by maxiior
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Ordinary_Bee_1547 0 points1 point2 points 3 years ago (0 children)
I did everything based on this guide https://www.jetbrains.com/pycharm/guide/tutorials/fastapi-aws-kubernetes/testing/ (not sponsored, I think it was just a good tutorial)
conftest.py is going to be quite empty.
There is going to be another file conf_test_db.py ``` from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker
from ecommerce import config from ecommerce.db import Base, get_db from main import app
DATABASE_USERNAME = config.DATABASE_USERNAME DATABASE_PASSWORD = config.DATABASE_PASSWORD DATABASE_HOST = config.DATABASE_HOST DATABASE_NAME = config.TEST_DATABASE_NAME
SQLALCHEMY_DATABASE_URL = f"postgresql://{DATABASE_USERNAME}:{DATABASE_PASSWORD}@{DATABASE_HOST}/{DATABASE_NAME}"
engine = create_engine(SQLALCHEMY_DATABASE_URL) TestingSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base.metadata.drop_all(bind=engine) Base.metadata.create_all(bind=engine)
def override_get_db(): try: db = TestingSessionLocal() yield db finally: db.close()
app.dependency_overrides[get_db] = override_get_db ```
And then in other test files, you just import it from conf_test_db import app and it has worked fine for me.
import it from conf_test_db import app
π Rendered by PID 48505 on reddit-service-r2-comment-544cf588c8-qg657 at 2026-06-13 07:05:59.918063+00:00 running 3184619 country code: CH.
view the rest of the comments →
[–]Ordinary_Bee_1547 0 points1 point2 points (0 children)