1.如何让某个case第一个执行
步骤1:requirement.txt中添加 pytest-ordering==0.6
步骤2:case title上添加@pytest.mark.run(order=1)
2.如何在终端执行pytest时添加参数
1)例如pytest -s -v test01.py --param="this is a param" -p no:warnings
def fun(request):
param = request.config.getoption("--param")
dict = {}
dict.update({'param': param})
return dict
定义完之后,就可以使用–param添加参数了,比如可以将yaml文件作为参数传入
2)如何只运行@pytest.mark.smoke的cases:
pytest -s -v -m smoke -p no:warnings
- 装饰符
def test_01(record_property):
record_property("ticket", "001")
3. parameter给每个case增加marks
import re
@pytest.mark.parametrize('state',
[pytest.param(0,
id="case0", marks=pytest.mark.sanity),
pytest.param(1,
id="case1", marks=pytest.mark.smoke)
])
def test_state(self, state):
logger.info("this is a case")
process_out, process_err = cmd('ps -ef |grep pytest')
match = re.compile("(\d{1,8}) root /opt/bin/pytest")
search = re.search(match, process_out)
if search:
pid = search.group(1)
cmd("kill -11 %s") % pid