Fork me on GitHub

pytest 学习 - 02 失败重新运行

前言

测试失败后要重新运行n次,要在重新运行之间添加延迟时间,间隔n秒再运行

安装:pip install pytest-rerunfailures

案例

import pytest


class TestDemo:
    def test_a(self):
        print("失败用例")
        assert 1 == 2

    def test_b(self):
        print("成功用例")
        assert 2 == 2


if __name__ == '__main__':
    pytest.main()

执行:
- 测试失败后重新运行2次:pytest --reruns 2 -v -s main.py

- 测试失败后重新运行3次且每次重新运行间隔1秒:pytest -v -s --reruns 3 --reruns-delay 1 main.py

 

posted @ 2024-05-13 09:59  测栈云  阅读(4)  评论(0编辑  收藏  举报