-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The odmantic engine do not change database in tests #57
Comments
Hey, sorry to hear you're running into this issue. Could you walk me through the steps you ran to execute your tests? @pytest_asyncio.fixture(scope="session")
async def db() -> Generator:
db = MongoDatabase()
print(db.name) # <----- This new line
_MongoClientSingleton.instance.mongo_client.get_io_loop = asyncio.get_event_loop
await init_db(db)
yield db in the test framework code? This will confirm if the database name is viewed as "test" in the tests. In the meantime, one workaround you can conduct to ensure the @pytest_asyncio.fixture(scope="session")
async def db() -> Generator:
db = _MongoClientSingleton()[TEST_DATABASE]
print(db.name) # <----- This new line
_MongoClientSingleton.instance.mongo_client.get_io_loop = asyncio.get_event_loop
await init_db(db)
yield db |
@Jibola It appears that since In the full-stack-fastapi-template, the code is implemented in that way. Were there any design considerations behind this approach? |
Our design consideration was that to prevent redundant client construction in the tool.
|
Thank you for reply. I think since there’s no need to dynamically switch the DB during operation, it seems unnecessary to change the CRUDBase reference, and simply receiving the created engine as an argument should be sufficient. |
Hi there,
I used this repository to develop my own app. When I ran tests, the database of the Odmantic engine did not change to the test database. I saw the database name was changed to the test name at this code, but the singleton engine is created at this file.
Therefore, the crud methods in unit tests still use production database.
The text was updated successfully, but these errors were encountered: