如何使用外部设备跳过pytest?

如何使用外部设备跳过pytest?,第1张

如何使用外部设备跳过pytest?

似乎py.test在评估的表达式时不使用测试装置

skipif
。以您的示例为例,
test_ios
它实际上是成功的,因为它会将模块名称空间中找到的
函数
platform
"ios"
字符串进行比较,该字符串求值
False
后将执行测试并成功。如果pytest如您期望的那样插入夹具进行评估,则应该跳过该测试。

解决您的问题(但不是解决您的问题)的方法是实施一种夹具,以检查测试中的标记,并相应地跳过它们:

# conftest.pyimport pytest@pytest.fixturedef platform():    return "ios"@pytest.fixture(autouse=True)def skip_by_platform(request, platform):    if request.node.get_closest_marker('skip_platform'):        if request.node.get_closest_marker('skip_platform').args[0] == platform: pytest.skip('skipped on this platform: {}'.format(platform))

关键是

autouse
参数,它将使该夹具被所有测试自动包括在内。然后,您的测试可以像这样标记要跳过的平台:

@pytest.mark.skip_platform('ios')def test_ios(platform, request):    assert 0, 'should be skipped'

希望有帮助!



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5646093.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-16
下一篇2022-12-16

发表评论

登录后才能评论

评论列表(0条)

    保存