ponyorm / pony

Pony Object Relational Mapper
Apache License 2.0
3.66k stars 245 forks source link

pony orm and pytest #617

Open tweigel-dev opened 3 years ago

tweigel-dev commented 3 years ago

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

sashaaero commented 3 years ago

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

tweigel-dev commented 3 years ago

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?

sashaaero commented 2 years ago

Yes, something like this

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