控制用例的執(zhí)行順序
下載插件:
pip install pytest-ordering
使用:
import pytest
@pytest.mark.run(order=3)
def test_case_02():
assert 1
@pytest.mark.run(order=4)
def test_case_01():
assert 1
@pytest.mark.run(order=1)
def test_case_03():
assert 1
class TestCase(object):
@pytest.mark.run(order=2)
def test_case_04(self):
assert 1
使用order參數(shù)來(lái)控制用例的執(zhí)行順序,注意的是,order參數(shù)是一個(gè)正整數(shù)。
失敗重試
失敗重試意思是指定某個(gè)用例執(zhí)行失敗可以重新運(yùn)行,為了避免某個(gè)接口本身么有問(wèn)題,但是由于網(wǎng)絡(luò)或其他原因?qū)е卤敬螠y(cè)試時(shí),失敗了,那么,我們需要對(duì)種接口進(jìn)行多次嘗試,以增加成功率。
下載
pip install pytest-rerunfailures
使用
在配置文件中的addopts添加一個(gè)參數(shù):
[pytest]
addopts = -s -v --reruns=3
當(dāng)某個(gè)接口斷言失敗,然后該接口最多嘗試重跑3次。當(dāng)在指定的次數(shù)之內(nèi),嘗試成功,后續(xù)的重跑不在執(zhí)行。如果嘗試次數(shù)重試完畢,但依然斷言失敗,則最終該接口判定為斷言失敗。
并發(fā)執(zhí)行
下載:
pip install pytest-xdist
使用
在配置文件中添加:
[pytest]
addopts = -v -s --html=report/report.html -n=auto
;addopts = -s --alluredir ./report/result
testpaths = ./scripts/
python_files = test_case_01.py
python_classes = Test*
python_functions = test_*
就是這個(gè)-n=auto:
-
-n=auto,自動(dòng)偵測(cè)系統(tǒng)里的CPU數(shù)目。 -
-n=numprocesses,也就是自己指定運(yùn)行測(cè)試用例的進(jìn)程數(shù)。
并發(fā)的配置可以寫在配置文件中,然后其他正常的執(zhí)行用例腳本即可。