pytest - rerun failed script

都知道有很多的因素会造成自动化脚本Failed,最好的方式是能在Failed后再自动的跑一下,以达到更好的自动化的效用。

Google发现有现成的,就直接用:pytest-rerunfailures

并用做了验证,没毛病:

  1. 准备用例

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    #coding=utf-8

    class TestClass:

    def test_one(self):
    x = "this"
    assert "h0" in x

    def test_two(self):
    x = "hello"
    assert x == "hello"
  2. 验证Rerun

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    C:\Python27\Scripts>py.test -r aR --rerun 2 1\1.py
    ============================= test session starts =============================
    platform win32 -- Python 2.7.13, pytest-3.2.3, py-1.4.34, pluggy-0.4.0
    rootdir: C:\Python27\Scripts, inifile:
    plugins: rerunfailures-3.1
    collected 2 items

    1\1.py RRF.
    =========================== rerun test summary info ===========================
    RERUN 1/1.py::TestClass::()::test_one
    RERUN 1/1.py::TestClass::()::test_one
    =========================== short test summary info ===========================
    FAIL 1/1.py::TestClass::()::test_one

    ================================== FAILURES ===================================
    _____________________________ TestClass.test_one ______________________________

    self = <1.TestClass instance at 0x03EA3C10>

    def test_one(self):
    x = "this"
    > assert "h0" in x
    E AssertionError: assert 'h0' in 'this'

    1\1.py:7: AssertionError
    ================= 1 failed, 1 passed, 2 rerun in 0.11 seconds =================
唐胡璐 wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
分享创造价值,您的支持将鼓励我继续前行!