当前位置:网站首页>pytest学习--base
pytest学习--base
2022-07-02 06:36:00 【迷途~知返】
pytest单元测试框架
单元测试是指在软件开发过程中,针对软件的最小单位(函数、方法)进行正确的检查测试
单元测试框架:
java:junit和testing
python:unnitest和pytest
单元测试框架主要做什么
- 测试发现:从多个文件里面去找找到我们的测试用例
- 测试执行:按照一定的顺序和规则去执行,并生成结果
- 测试判断:通过断言判断预期结果和世界结果的差异
- 测试报告:统计测试进度,耗时,通过率,生成测试报告
单元测试框架和自动化测试框架有什么关系 - 什么是自动化测试框架:去完成整个系统的完善的代码的框架,封装自动化的基础模块,管理模块
- 作用
- 提高测试效率,较低维护成本
- 减少人工干预,提高测试的准确性,增加代码的重用性
- 核心思想是让不懂代码的人也能通过这个框架去实现自动化测试
- pytest单元测试和自动化测试框架的关系
- 单元测试框架:
- pom设计模式
- 数据驱动
- 关键字驱动
- 全局配置文件的封装
- 日志监控
- selienium,requests
- 断言
- 报告邮件
pytest简介
1、pytest是一个非常成熟的python单元测试框架,比unnitest简单
2、pytest可以和selinum,requests,appinum结合实现web自动化,接口自动化,APP自动化
3、pytest可以实现测试用例的跳过以及returns失败用例的重试
4、pytest可以和allture生成非常美观的测试报告
5、pytest可以和jenkins持续集成
6、pytest有很多非常强大的插件,并且这些插件能够实现很多的使用的操作
- pytest
- pytest-html(生成html格式的自动化测试报告)
- pytest-xdist 测试用例分步执行,多cpu分发
- pytest-ordering 用于改变用例的执行顺序
- pytest-returning 用例失败后重跑
- allure-pytest 用于生成美观的测试报告
- 放到requirement.txt文件中通过pip install -r requirement.txt
使用pytest,默认的测试用例的规则以及基础应用
- 1、模块名必须以test_或者_test结尾
- 2、测试类必须以Test开头,不能有__init__方法
- 3、测试方法必须以test开头
pytest测试用例的运行方式
主函数模式运行
-运行所有:pytest.main()
指定模块:pytest.main([‘-vs’,‘test_login.py’])
指定目录运行:pytest.main([‘-vs’,‘./interface/test_01_inter.py’])
通过nodeid指定用例运行:node由模块名,分隔符,类名,方法名,函数名组成命令行模式运行
-运行所有pytest
指定模块运行 pytest -vs test_login.py
指定目录运行:pytest -vs ./interface/test_01_inter.py
参数详解:
-s:输出调试的信息包括print打印的信息
-v:显示更加详细的信息
-vs:这两个参数一起使用
-n:支持多线程或者分布式运行测试用例
pytest -vs ./testcase/test_login.py -n 2
-x:表示只要有一个用例报错,那么测试停止
-k:根据测试用例的部分字符串指定测试用例
如:pytest -vs ./testcase -k “ao”
–html 生成html报告通过读取pytest.ini配置文件运行
-pytest.ini这个文件他是pytest单元测试矿建的核心配置文件
-位置:一般放在项目的根目录
-编码:ASCII编码,可以使用nopad++修改编码格式
-作用:改变pytest默认的行为
-运行规则:不管是主函数的运行模式,命令行模式运行,都回去读取这个配置文件
[pytest]
addopts=-vs # 命令行参数是
testpaths=./testcase # 测试用例的路径
python_files = test_*.py # 模块名的规则
python_classes = Test* # 类名的规则
python_functions = test # 方法名的规则
marks =
smoke:冒烟用例
usermanage:用户管理模块
六、pytest执行测试用例的顺序:
默认执行方式是从上到下依次执行
加标记执行
分组执行(冒烟,接口,web)
smoke:猫眼用例,分布在各个模块里面
pytest -m “smoke”
pytest -m "smoke or usermanage"t
跳过测试用例
(1)无条件跳过
pytest.mark.skip(reason="xxxx")
class TestCar:
age = 20
@pytest.mark.skip(reason="xxxxxx")
def test_01_car(self):
print("this is old car")
(2)有条件跳过
class TestCar:
age = 20
@pytest.mark.skipif(age>=18,reason="xxxxxxx")
def test_01_car(self):
print("this is old car")
pytest.mark.skipif(age>=18,reason="xxxxxxx")
边栏推荐
- Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
- Project practice, redis cluster technology learning (13)
- Notes de base sur les plans illusoires d'IA (triés en 10 000 mots)
- Blender石头雕刻
- 虚幻材质编辑器基础——如何连接一个最基本的材质
- It is the most difficult to teach AI to play iron fist frame by frame. Now arcade game lovers have something
- Spatial interpretation | comprehensive analysis of spatial structure of primary liver cancer
- 2837xd代码生成模块学习(4)——idle_task、Simulink Coder
- The latest progress and development trend of 2022 intelligent voice technology
- 【Unity3D】制作进度条——让Image同时具有Filled和Sliced的功能
猜你喜欢
Introduction et prévention des essais de pénétration
Large neural networks may be beginning to realize: the chief scientist of openai leads to controversy, and everyone quarrels
【虚幻】按键开门蓝图笔记
Notes de base sur les plans illusoires d'IA (triés en 10 000 mots)
UE5——AI追逐(蓝图、行为树)
[unreal] animation notes of the scene
Tee command usage example
【JetBrain Rider】构建项目出现异常:未找到导入的项目“D:\VisualStudio2017\IDE\MSBuild\15.0\Bin\Roslyn\Microsoft.CSh
Skywalking theory and Practice
2837xd代码生成模块学习(4)——idle_task、Simulink Coder
随机推荐
Ctrip starts mixed office. How can small and medium-sized enterprises achieve mixed office?
MySQL -- time zone / connector / driver type
UE5——AI追逐(藍圖、行為樹)
[IDL] Research
Applet development summary
How much is it to develop a system software in Beijing, and what funds are needed to develop the software
Introduction and prevention of penetration test
[ue5] animation redirection: how to import magic tower characters into the game
go语言入门
This monitoring system makes workers tremble: turnover intention and fishing can be monitored. After the dispute, the product page has 404
Vscode set JSON file to format automatically after saving
虚幻材质编辑器基础——如何连接一个最基本的材质
A model can do two things: image annotation and image reading Q & A. VQA accuracy is close to human level | demo can be played
阿里云ack介绍
AutoCAD - layer Linetype
How to handle error logic gracefully
C language strawberry
MySQL index
2837xd code generation - stateflow (2)
Minimum number of C language