pytest-repeat是pytest的插件:(pytest-repeat 無法支持使用unittest.TestCase測試類)
作用:
用於重復執行單個用例,或多個測試用例,並指定重復次數,
安裝:
pip install pytest-repeat
使用:
--count命令,指定要運行測試用例和測試次數:pytest --count=10 test_demo.py
注:
--repeat-scope類似於 @pytest fixture()的scope參數,
--repeat-scope也可設置參數: 默認的function、module、session 、class
使用:pytest test_demo.py -s --count=5 --repeat-scope=session
另:
結合使用mark標記來重復執行:
@pytest.mark.repeat(count)
使用:@pytest.mark.repeat(3) #在要重復執行的case上加上這個裝飾器即可,運行時會默認運行指定次數3