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
I'm using a free Postgres database provided by ElephantSQL. I cant seem to figure out the tear down part of the fixture.
Methods I've tried with their respective errors I encountered:
Docs: Pytest encounters (asyncpg: ObjectInUse) exception while running, the first Tortoise._drop_databases() in the initializer(). This is a recurring theme, whenever I try to use anything with Tortoise._drop_databases() pytest seems to throw the same error.
Next way I choose to intialise the database is using Tortoise.init() fortunately enough, the test database is initialized with no problem ( using _create_db=True throws an tortoise.exceptions.OperationalError: permission denied to create database ). The test runs without any errors. But I cannot figure out the teardown code for resetting the database to its original state. I can use Tortoise.close_connections() but that just closes the connections, not removing the data in the test database. Not having proper teardown code, results in the data being stored in the database and the tests fail the second time I run them as the username field is unique.
I've tried using User.all().delete() in the beginning but I have too many tables to do that manually for every table. And this does not work if I manually change my User model a bit, say adding a new temp field ( I have limited knowledge on databases but this is probably due to conflicting schemas ).
I want the tear down code of the fixture to completely reset the database to its empty state.
Thanks, for anyone who helps. You can request more info if required.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm using a free Postgres database provided by ElephantSQL. I cant seem to figure out the tear down part of the fixture.
Methods I've tried with their respective errors I encountered:
Tortoise._drop_databases()
in theinitializer()
. This is a recurring theme, whenever I try to use anything withTortoise._drop_databases()
pytest seems to throw the same error.Tortoise.init()
fortunately enough, the test database is initialized with no problem ( using_create_db=True
throws antortoise.exceptions.OperationalError: permission denied to create database
). The test runs without any errors. But I cannot figure out the teardown code for resetting the database to its original state. I can useTortoise.close_connections()
but that just closes the connections, not removing the data in the test database. Not having proper teardown code, results in the data being stored in the database and the tests fail the second time I run them as theusername
field is unique.User.all().delete()
in the beginning but I have too many tables to do that manually for every table. And this does not work if I manually change myUser
model a bit, say adding a newtemp
field ( I have limited knowledge on databases but this is probably due to conflicting schemas ).I want the tear down code of the fixture to completely reset the database to its empty state.
Thanks, for anyone who helps. You can request more info if required.
Beta Was this translation helpful? Give feedback.
All reactions