【发布时间】:2017-10-24 10:35:01
【问题描述】:
在 ORM.py 文件中:
from peewee import *
db = SqliteDatabase('database.db')
class Device(Model):
uid = CharField(unique=True, max_length=17)
class Meta:
database = db
现在在 test.py 中,我想用 test.db 猴子补丁原始数据库 database.db
from _pytest.monkeypatch import MonkeyPatch
@pytest.fixture(scope="session")
def monkeysession(request):
mp = MonkeyPatch()
yield mp
mp.undo()
@pytest.fixture(scope='session', autouse=True)
def create_db(monkeysession, request):
monkeysession.setattr(ORM, 'db', SqliteDatabase('test.db'))
但我的错误(peewee.OperationalError: table "device" already exists)提示monkeypatch失败
【问题讨论】:
标签: python-3.x mocking pytest peewee