- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我需要为我的 Django 应用程序编写一些测试。为此,我使用的是这样加载的装置:
from django.test import TestCase
class PermissionTest(TestCase):
fixtures = ['test_groups.json','test_users.json']
def setUp(self):
... some other stuff
现在我想知道在我的tearDown-Method 中写什么来删除从我的装置生成的组和用户。或者它们会被自动删除?
def tearDown(self):
... what has to go here?
最佳答案
在运行每个测试之前,django 的测试框架将删除已加载的装置。所以你不需要处理这个。
来自docs :
Here’s specifically what will happen:
At the start of each test case, before setUp() is run, Django will flush the database, returning the database to the state it was in directly after migrate was called.
Then, all the named fixtures are installed. In this example, Django will install any JSON fixture named mammals, followed by any fixture named birds. See the loaddata documentation for more details on defining and installing fixtures.
This flush/load procedure is repeated for each test in the test case, so you can be certain that the outcome of a test will not be affected by another test, or by the order of test execution.
关于Python Django 单元测试 : How to tear down fixtures,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21550032/
我正面临 pytest 固定装置的一个小问题,感谢您的帮助。 我有一些功能装置,如下所述。为简单起见,我没有展示实现。 @pytest.fixture() def get_driver():
我有一个现有的 pytest使用一些预定义列表来测试它们的交叉产品的测试: A_ITEMS = [1, 2, 3] B_ITEMS = [4, 5, 6] C_ITEMS = [7, 8, 9] 我还
我要传一个pytest.fixture函数到另一个 fixture 函数的 param 参数。像这样的东西: @pytest.fixture() def foo(): return "foo"
我试图避免在我的测试中重复太多的样板文件,我想以更有条理的方式重写它们。假设我有两个不同的解析器,它们都可以将文本解析为 doc。然后该文档将用于其他测试。最终目标是公开一个可以在其他测试中使用的 d
我有很多通过 pytest 管理的参数化装置。 有时,我希望使用 fixture 的测试不必担心应用参数。 是否可以制作一个参数化另一个 fixture 的 fixture ? import pyte
我有一对 fixture 用于测试具有 x-y 输入的函数。一个生成 x 值,另一个生成 y 值。测试取决于两者。 y 值也取决于 x 值。以下是设置摘要: import pytest @pytest
例子: from pytest import fixture, skip @fixture(params=['a', 'b']) def f1(request): yield request.
我的 Karma 配置文件中的文件属性是 files: [ // Program files 'public/js/init.js',
Conftest.py @pytest.fixture(scope="module") def fixture2(request): do something @pytest.fixture(
我正在使用 unittest.mock 模拟一个 API。我的界面是一个在后台使用 requests 的类。所以我正在做这样的事情: @pytest.fixture def mocked_api_an
基于此堆栈溢出:pytest fixture of fixtures 我在同一个文件中有以下代码: @pytest.fixture def form_data(): return { ...
命令行 python3 -m pytest src/spec/ --app=android conftest.py import pytest def pytest_addoption(parser)
我正在对我的代码进行一些测试,我得到了我的第一个“停止”,因为我不知道如何继续前进。在我加载灯具的 setUp() 函数中看到: public function setUp() { stati
我在两种模式下运行测试:裸 pytest 和 pytest-xdist。我有一个用模块范围定义的重型 fixture 。在这个 fixture 中,我对使用 xdist 运行测试的情况进行了一些优化:
我想在相同参数化测试的不同实例化之间共享 fixture,其中 fixture 本身也被参数化: #!/usr/bin/py.test -sv import pytest numbers_for_fi
我有一个包含多个 JSON 文件的 AWS S3 目录,这些文件用作测试输入。 我创建了一个 PyTest 模块,它使用模块范围的 fixture 下载所有 JSON 文件一次,然后运行多个测试函数
我有一个固定装置,它返回该端点名称(传入)的端点 名称是测试中设置的字符串。我在测试中每次调用端点(参数化)都搞砸了,现在我不知道如何在不每次调用端点的情况下获得相同的功能。 基本上,我只需要调用一次
如果我有两个参数化的 fixture ,我如何创建一个测试函数,首先用一个 fixture 的实例调用,然后用另一个 fixture 的实例调用? 我想创建一个以某种方式连接两个现有装置的新装置是有意
我是python的新手。我已经声明了一个装置 configure_loggers()范围为“ session ”。现在,我想在另一个 fixture 之前使用这个 fixture setup_app(
我想在另一个固定文件中实例化的固定文件中使用一个对象。类似于以下内容(不起作用): monitor_france: objecttype_id: 2 name1: i-france-1 n
我是一名优秀的程序员,十分优秀!