pytest之安装和基础使用方法
Pytest:
搜索规则:
- 符合命名规则 test_*.py 或者*_test.py的文件
- 以test_开头的函数名
- 以Test开头的测试类(没有_init__函数)中,以test_开头的函数名
对用例打标签:
@pytest.mark.标签名
公有化:
Conftest.py配置文件
前置条件 @pytest.fixtures(scoup=”class”)
例:
@pytest.fixtures(scoup=”class”)
Def access_web():
Global driver
Driver=webdriver.Chrome()
Lg=LoginPage(driver)
Yield (driver,lg) #分割线 #后面接返回值
Driver.quit()
使用前置条件
@pytest.mark.usefixtures(“函数名”)
参数化
@pytest.mark.parametrize(“参数名”,”列表数据”)
重运行
安装插件pip install pytest-rerunfailures
命令行执行命令:
pytest -m demo --reruns 2 --reruns-delay 5 -s --junitxml=OutPut/report.xml
生成报告
pytest -m demo --reruns 2 --reruns-delay 5 -s --junitxml=OutPut/report/report.xml --html=OutPut/report/html_report.html
打标签@pytest.mark.smoke (and/not)---> 运行pytest -m smoke 根据位置顺序来执行