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
运行截图:
不要当自己回首过去,除了蹉跎岁月,一无所有。