Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
pytestfixture:让数据持久化(Django)_Django_Pytest_Pytest Django - Fatal编程技术网

pytestfixture:让数据持久化(Django)

pytestfixture:让数据持久化(Django),django,pytest,pytest-django,Django,Pytest,Pytest Django,我喜欢pytest django装置,并在django应用程序中使用它们 但有时我希望有数据可以利用 到目前为止,pytest fixture仅在临时数据库中 我的目标是:我希望在django web GUI中有一个按钮。如果我按下按钮 按钮我的pytest装置列表应该在普通数据库中调用 如果我尝试在django视图中直接调用fixture,我会得到以下消息: Failed: Fixture "waiting_for_activation_user" called direc

我喜欢pytest django装置,并在django应用程序中使用它们

但有时我希望有数据可以利用

到目前为止,pytest fixture仅在临时数据库中

我的目标是:我希望在django web GUI中有一个按钮。如果我按下按钮 按钮我的pytest装置列表应该在普通数据库中调用

如果我尝试在django视图中直接调用fixture,我会得到以下消息:

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\u或\u create()
的帮助下实现“创建测试数据”按钮。但那不好,因为 我需要实现两次测试数据的创建


有没有人有解决方案,这样我只需要编写一次代码来创建测试数据,并且我可以使用它两次(一次用于pytext fixture,一次用于按钮)?

我会将您希望在普通web应用程序中使用的fixture部分提取到某种类型的factory模块或类中。然后针对新零件编写测试,以确认工厂按照预期工作

但是,我不会尝试在web应用程序中直接使用pytest夹具