Replies: 1 comment
-
Seems like the following solution works, but still curious if anyone has something better! for Model in project.db_models.__dict__.values():
if hasattr(Model, "ormar_config"):
mocker.patch.object(Model.ormar_config, "metadata", test_metadata)
mocker.patch.object(Model.ormar_config, "database", test_db) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a project that uses fastapi + ormar + pytest. To keep tests isolated in unit tests, I implement a pytest fixture that patches the ormar BaseMeta object to have a new SQLite database for each test. However this approach no longer works reliably with ormar 0.20.0 because of the way each model has it's own separate OrmarConfig (due to OrmarConfig.copy behavior)
Here's the code for the current approach:
In 0.20.0 there is no longer a centralized BaseMeta I can patch, instead there is a OrmarConfig and each model gets a separate instance due to OrmarConfig.copy. Does anyone have recommendations on the most reliable way for each test to get it's own database/metadata instances across all models in the newer 0.20.0 paradigm?
Beta Was this translation helpful? Give feedback.
All reactions