我有一个函数和一个测试
def foo(a):
return bar(a)
@pytest.mark.parametrize(
'number',
[1,2,3]
)
@pytest.mark.dependency
def test_foo(number):
assert foo(number) > SOME_CONST # Simplistic example, real case is more nuanced
Run Code Online (Sandbox Code Playgroud)
我正在使用 pytest 和 pytest_dependency 模块。foo是许多其他测试中使用的函数。我有一个函数,我想依赖它test_foo,下面的代码不起作用:
@pytest.mark.dependency(depends=['test_foo'])
@pytest.mark.parametrize(
'param',
itertools.permutations(['a','b','c','d','e'],2),
ids=repr,
)
def test_bar(param):
...
important_result = foo(param)
...
Run Code Online (Sandbox Code Playgroud)
理论上来说,如果test_foo失败,那么test_bar就会被跳过。但是,当我参数化 时,无论 的结果如何,都会跳过 的test_bar每个实例化。test_bartest_foo
澄清一下,此代码按预期工作(未跳过 test_bar):
@pytest.mark.dependency(depends=['test_foo'])
def test_bar():
param = some_fnc(['a', 'b'])
...
important_result = foo(param)
...
Run Code Online (Sandbox Code Playgroud) 我有一个功能测试套件,使用 pytest-dependency 来在它们依赖的其他测试失败时跳过测试。这样,例如,如果登录页面损坏,我会收到一个测试失败,提示“登录页面损坏”,而不是一系列测试失败提示“我无法登录用户 X”、“我无法登录”。登录用户 Y”等
这对于运行整个套件非常有用,但我正在尝试缩短我的编辑-编译-测试循环,而现在最慢的点是测试我的测试。如果我正在进行的测试有许多它所依赖的其他测试,那么它们都必须成功才能不跳过我正在尝试测试的测试。因此,我要么必须运行整个依赖关系树,要么注释掉我的@pytest.mark.dependency(...)装饰器(这是我作为一个人必须记住要做的另一件事)。从技术上讲,这些依赖的测试没有做任何事情来使它们的依赖者能够运行 - 我想要这些依赖项的唯一原因是为了让我更容易对测试失败进行分类。
是否有一个命令行参数可以告诉 pytest-dependency 不要因依赖项而跳过某些内容,或者告诉 pytest 在本次运行(并且仅此运行)中不要使用 pytest-dependency 插件?