如果你还想从头学起Pytest,可以看看这个系列的文章哦!
https://www.cnblogs.com/poloyy/category/1690628.html
pip3 install pytest-repeat -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
结合之前讲到的失败重跑、输出html报告插件来敲命令行
两种方式皆可,等号或空格
pytest --html=report.html --self-contained-html -s --reruns=5 --count=2 10fixture_request.py
-x
py.test --count=1000 -x test_file.py
def test_example():
import random
flag = random.choice([True, False])
print(flag)
assert flag
pytest -s --count 5 -x 13repeat.py
如果要在代码中将某些测试用例标记为执行重复多次,可以使用 @pytest.mark.repeat(count)
@pytest.mark.repeat(5)
def test_repeat():
print("测试用例执行")
pytest -s 13repeat.py
命令行参数
作用:可以覆盖默认的测试用例执行顺序,类似fixture的scope参数
class Test_repeat:
def test_repeat3(self):
print("测试用例执行333")
class Test_repeat2:
def test_repeat3(self):
print("测试用例执行444")
pytest -s --count=2 --repeat-scope=class 13repeat.py
def test_repeat1():
print("测试用例执行111")
def test_repeat2():
print("测试用例执行222")
class Test_repeat:
def test_repeat3(self):
print("测试用例执行333")
pytest -s --count=2 --repeat-scope=module 13repeat.py
pytest-repeat不能与unittest.TestCase测试类一起使用。无论--count设置多少,这些测试始终仅运行一次,并显示警告