微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Pytest

测试文件的命名规则

1.测试文件应该命名为test_<something>.py或者<something>_test.py

2.测试类应该命名为Test<something>.py

3.测试函数和测试类方法应该命名为test_<something>

Pytest 基础命令

pytest --hlep 可以查看pytest相关命令

import pytest

@pytest.mark.smoke
def test_mark_smoke():
    print('the aim is test mark smoke')


@pytest.mark.get
@pytest.mark.smoke
def test_mark_get_smoke():
    print('the aim is testing mark smoke and get')

只需要在命令中指定-m mark_name 就可以运行

比如Pycharm 的Terminal中输入pytest -v -m smoke test.py

跳过测试pytest.mark.skip(reason='misunderstood the API')

标记预期失败的测试pytest.mark.xfail(reason= misunderstood the API)
xfail表示的是预期会失败,但实际上也失败了,xpass表示的是预期会失败,但实际上是运行并没有失败

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐