【发布时间】:2015-03-17 19:34:09
【问题描述】:
我有一个依赖于名为fixture 的夹具的测试。大致是它的代码:
def test_optional_cool_feature(fixture):
if not fixture.supports_cool_feature():
return
assert cool_feature() == expected_result
这里的fixture 是一个参数化的夹具,它存在于 N 个变体中并声明为
@py.test.fixture(scope="session", params=["type1", ...])
def fixture(request):
if request.param = "type1":
return Type1()
elif ...
但是,当针对不支持cool_feature 的夹具运行测试时,在py.test 输出中看到测试被跳过(而不是PASSED)也很好。不幸的是,@py.test.mark.skipif('not fixture.supports_cool_feature()') 无法实现这一点,因为fixture 在执行skipif 时仍然是一个函数,而不是替代的测试参数。
【问题讨论】: