栏目分类:
子分类:
返回
文库吧用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
文库吧 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用外部设备跳过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'

希望有帮助!



转载请注明:文章转载自 www.wk8.com.cn
本文地址:https://www.wk8.com.cn/it/640291.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 wk8.com.cn

ICP备案号:晋ICP备2021003244-6号