pytest单元测试框架--几种常用的运行模式六

1、运行后生成测试报告、

安装pytest-html插件:

运行模式:

测试报告截图:报告中体现了测试结果 和 失败原因,很清晰

2、运行指定的case

class TestClassOne():
    def test_one(self):
        assert 'he' in 'hello'
    def test_two(self):
        assert 1+1 == 2

class TestClassTwo():
    def test_one(self):
        assert 'ip' in 'iphone'
    def test_two(self):
        assert 3+3 > 5

(1)pytest test_zhiding.py 会运行所有的测试用例

(2)pytest test_zhiding.py::TestClassOne 运行 指定测试类下面的测试用例

(3)pytest test_zhiding.py::TestClassOne::test_two 运行指定类 下面 指定的测试用例

3、多进程运行用例:在运行很多cases时,运行时间会很长,如果想缩短脚本运行的时间,可以用多进程来运行

安装pytest-xdist插件


运行模式:
pytest test_se.py -n NUM :NUM代表并发的进程数

4、重试运行用例:有时因为服务器原因或者网络不稳定,导致我们的用例得不到期望的结果,这时可以重试用例

安装pytest-rerunfailures插件


运行模式:
pytest test_se.py --reruns NUM :NUM代表重试的次数

5、输出代码中的print内容,方便调试

运行模式:pytest test_zhiding.py -s
运行截图:

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

相关推荐