发布: 更新时间:2022-09-06 22:50:17
安装库:pip install pytest
pytest相关插件:(了解)
完美报告:allure-pytest插件,allure报告插件(重点)
示例:assert "a" in "abc"
描述 | 前置 | 后置 |
---|---|---|
模块级,开始于模块始末,全局 | setup_module | teardown_module |
函数级,只用函数用例生效(不在类中的) | setup_function | teardown_function |
类级,只在类中前后运行一次(在类中) | setup_class | teardown_class |
方法级,每个方法用例前后执行(在类中) | setup_method | teardown_method |
测试用例或测试类前加skip装饰器,可跳过执行
@pytest.mark.skip
@pytest.mark.skipif() #满足条件才跳过
不论是主函数模式还是命令行模式都会优先读取这个配置文件来执行命令。
[pytest]
# 命令行参数,用空格分隔
addopts = -vs
# 定义标签
markers= p0:高优先级
p1:中优先级
# 测试用例文件夹,可以自己配置
testpaths = ./test_demo
# 配置测试搜索的模块文件名称
python_files = test*.py
# 配置测试搜索的类名
python_classes = test*
# 配置搜索的函数名
python_functions = test
主函数模式
import pytest
if __name__ == '__main__':
pytest.main() #运行所有的用例
# 指定模块运行
pytest.main(['-vs', 'test_login.py'])
# 指定目录
pytest.main(['-vs','./interface_testcase'])
# 通过nodeid指定用例运行:nodeid由模块名,分隔符,类名,方法名,函数名 组成,比如:
pytest.main(['-vs','./interface_testcase/test_interface.py::test_04_func'])
pytest.main(['-vs','./interface_testcase/test_interface.py::TestInterface::test_04_func'])
命令行模式
# 运行所有的用例:
pytest
# 指定模块运行:
pytest -vs test_login.py
# 指定目录:
pytest -vs ./interface_testcase
# 通过nodeid指定用例运行:nodeid由模块名,分隔符,类名,方法名,函数名 组成
pytest -vs ./interface_testcase/test_interface.py::TestInterface::test_04_func
安装pytest的allure插件:pip install allure-pytest
#执行pytest,生成allure所需要的数据源。--alluredir设置数据源存放目录
pytest --alluredir=./allure-results
# 执行此命令,将在默认浏览器中显示生成的报告
allure serve ./allure-results
标签:pytest, 测试框架, 自动化测试, 软件测试 原神3.8心海武器推荐 原神3.8心海带什么武器
阴阳师寻迹骰怎么获得 阴阳师寻迹骰获得方法
王者荣耀妄想都市观光怎么获得 王者荣耀妄想都市观光活动
阴阳师新召唤屋和幕间皮肤效果怎么样 阴阳师新召唤屋和幕间皮肤获取方法介绍
羊了个羊7.26攻略 羊了个羊7月26日怎么过
崩坏星穹铁道求不得成就攻略介绍 崩坏星穹铁道求不得成就怎么获得
崩坏星穹铁道去吧阿刃成就攻略介绍 崩坏星穹铁道去吧阿刃成就怎么获得
时空中的绘旅人罗夏生日有什么复刻 绘旅人罗夏生日礼包复刻一览
银河境界线武器强度怎么看 银河境界线武器强度排行攻略
阴阳师红蛋蛋限时福利怎么获得 阴阳师再结前缘版本福利介绍