pytest实现失败重新运行机制

2020-08-09  本文已影响0人  成功在于实践
# test_002.py
import pytest

def test_001():
    print('我执行了1')
    assert 0==1
def test_002():
    print('我执行了2')
    assert 0==0
def test_003():
    print('我执行了3')
    assert 0==0
def test_004():
    print('我执行了4')
    assert 0==1
if __name__ == '__main__':
    pytest.main(['-s','test_002.py'])
 # --lf, --last - failed - 只重新运行上次失败的用例,如果没有失败则全部运行

# --ff, --failed - first - 先运行故障然后再运行其余的测试。
第一次执行:  pytest    --lf   test_002.py
image.png
第二次执行:  pytest    --lf   test_002.py
image.png

注意:清除之前的缓存

image.png
第一次执行:  pytest    --ff   test_002.py
image.png
第二次执行:  pytest    --ff   test_002.py
image.png
上一篇 下一篇

猜你喜欢

热点阅读