admin管理员组文章数量:1419185
I have seen TestCase.setUpTestData which improves test speed quite a bit in my case.
I typically prefer pytest fixtures instead of the TestCase classes. However,when I make a session-scope fixture which does data preparation needed for all tests with the fixture, I get
RuntimeError: Database access not allowed, use the "django_db" mark, or the "db" or "transactional_db" fixtures to enable it.
I followed , but that had no effect.
How can I store and re-use a DB state within a Django application when testing using pytest?
I use an in-memory sqlite3 DB.
I tried :
@pytest.mark.django_db
@pytest.fixture(scope='session')
def thing(django_db_setup, django_db_blocker):
del django_db_setup # Cannot be used with usefixtures(..) it won't work
with django_db_blocker.unblock():
print('sleeping')
Thing.objects.create(thing='hello')
and expected the test to run successfully + save time. Instead, I got the RuntimeError mentioned above.
(function-scoped fixtures work fine, but then I don't save any test execution time)
本文标签: pythonWhat is pytests equivalent to setUpTestData in DjangoStack Overflow
版权声明:本文标题:python - What is pytests equivalent to setUpTestData in Django? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745305525a2652621.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论