Вы можете использовать методы Database.bind()
или Database.bind_ctx()
, которые документированы:
http://docs.peewee -orm.com / ru / latest / peewee / api.html # Database.bind_ctx
Документация охватывает этот точный сценарий:
MODELS = (User, Account, Note)
# Bind the given models to the db for the duration of wrapped block.
def use_test_database(fn):
@wraps(fn)
def inner(self):
with test_db.bind_ctx(MODELS):
test_db.create_tables(MODELS)
try:
fn(self)
finally:
test_db.drop_tables(MODELS)
return inner
class TestSomething(TestCase):
@use_test_database
def test_something(self):
# ... models are bound to test database ...
pass