You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
Hey, sorry to hear you're running into this issue.
Could you walk me through the steps you ran to execute your tests?
Additionally, when you run this test script, could you add
@pytest_asyncio.fixture(scope="session")asyncdefdb() ->Generator:
db=MongoDatabase()
print(db.name) # <----- This new line_MongoClientSingleton.instance.mongo_client.get_io_loop=asyncio.get_event_loopawaitinit_db(db)
yielddb
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 test database is being called is either calling the _MongoClientSingleton object directly and yielding that in the asyncio fixture like below:
@pytest_asyncio.fixture(scope="session")asyncdefdb() ->Generator:
db=_MongoClientSingleton()[TEST_DATABASE]
print(db.name) # <----- This new line_MongoClientSingleton.instance.mongo_client.get_io_loop=asyncio.get_event_loopawaitinit_db(db)
yielddb
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: