问题描述
我喜欢 pytest-django 固定装置并在我的 django 应用程序中使用它们。
但有时我想玩玩数据。
目前pytest的fixture只存在于临时数据库中。
我的目标:我想在我的 django-web GUI 中有一个按钮。如果我按下 按钮应该在普通数据库中调用我的 pytest 设备列表。
如果我尝试在 django 视图中直接调用装置,我会收到以下消息:
Failed: Fixture "waiting_for_activation_user" called directly. Fixtures are not meant to be called directly,but are created automatically when test functions request them as parameters.
See https://docs.pytest.org/en/stable/fixture.html for more information about fixtures,and
https://docs.pytest.org/en/stable/deprecations.html#calling-fixtures-directly about how to update your code.
当然我可以忽略测试装置的存在,并在 Django ORM 方法 update_or_create()
的帮助下实现“创建测试数据”按钮。但这并不好,因为
我需要实现两次测试数据的创建
有没有人有解决方案,所以我只需要编写代码来创建测试数据一次,并且我可以使用它两次(一次用于 pytext 固定装置,一次用于按钮)?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)