pony icon indicating copy to clipboard operation
pony copied to clipboard

pony orm and pytest

Open tweigel-dev opened this issue 3 years ago • 3 comments

Hay thanks for the great orm mapper. I have a issue using it within pytest. If I run the test first time everything is fine and works perfectly. After run the same couple of test again I got

pony.orm.core.BindingError: Database object was already bound to PostgreSQL provider

It seems that the state of the connection/session is saved beyond the process livetime of pytest. Currently I always have to restart the database to kill this established session....

Is there something wrong at Ponyorm or have you a hint how this behavior can be resolved?

Thanks in advance, Thomas

tweigel-dev avatar Nov 15 '21 10:11 tweigel-dev

Hello. It means you use db.bind twice or more in your code. You can recreate Database instance for each test.

sashaaero avatar Nov 29 '21 07:11 sashaaero

I do multiple Database instances and I get the already bind error. It is possible to check if it is already bind to avoid this issue?

tweigel-dev avatar Nov 30 '21 15:11 tweigel-dev

Yes, something like this

def is_bound(db):
    return db.provider is not None

sashaaero avatar Dec 04 '21 17:12 sashaaero