Pytest学习笔记4——测试步骤
2023-06-13 09:16:50 时间
引言
大家都知道功能测试用例组成的基本要素:用例ID,模块名,测试用例名称,前置条件,测试步骤,预期结果,实际结果等等。前置条件以及测试参数化,前面已经讲过,现在简单讲一下pytest测试步骤的用法。
案例
如果想在报告中展示测试步骤,需要使用装饰器@allure.step(),该装饰器写在测试步骤函数上面,测试方法直接调用测试步骤函数即可。具体看代码:
import allure
@allure.step("第一步")
def step_1():
step_2()
print("打开浏览器")
@allure.step("第二步")
def step_2():
step_3()
print("输入URL")
@allure.step("第三步")
def step_3():
step_4(username='test',password=123456)
print("输入账号和密码")
pass
@allure.step('第四步:登录')
def step_4(username,password):
print("登录")
print(username,password)
@allure.step("第五步")
def test_login():
step_1()
运行结果:
输入命令:pytest -s --alluredir allure_report
================================================================================= test session starts ==================================================================================
platform win32 -- Python 3.6.5, pytest-5.4.1, py-1.7.0, pluggy-0.13.1
rootdir: C:\Users\Administrator\Desktop\pytest_test_2019\test_pytest
plugins: allure-pytest-2.8.13, celery-4.3.0, cov-2.7.1, forked-1.1.3, html-1.20.0, metadata-1.8.0, rerunfailures-5.0, xdist-1.32.0
collected 1 item
test_step.py 登录
test 123456
输入账号和密码
输入URL
打开浏览器
.
================================================================================== 1 passed in 0.06s ===================================================================================
输入命令:allure serve allure_report
Report successfully generated to C:\Users\ADMINI~1\AppData\Local\Temp\6826110311791803428\allure-report
Starting web server...
2020-06-05 23:41:51.453:INFO::main: Logging initialized @2015ms to org.eclipse.jetty.util.log.StdErrLog
Server started at <http://192.168.1.105:49560/>. Press <Ctrl+C> to exit
自动打开浏览器,查看报告:
总结
@allure.step()基本用法就是这样,建议嵌套使用,单独使用的意义并不大。
另外,对测试开发,自动化测试,全栈测试相关技术感兴趣的朋友,可以加入到群里学习和探索交流,进群方式,扫下方二维码。
相关文章
- pytest生成最美测试报告
- pytest学习及资料
- pytest 中fixture传递参数到case中
- pytest的使用_实例调用和类调用
- Pytest(17)运行未提交的git(pytest-picked)
- pytest运行_python缓存机制
- pytest的assert_assert断言语句
- pytest指定用例_pytest执行多个py文件
- pytest学习和使用17-Pytest如何重复执行用例?(pytest-repeat)
- 测试之路 pytest接口自动化框架-yaml数据
- pytest文档82 - 用例收集钩子 pytest_collect_file 的使用
- pytest + yaml 框架 -17.文件上传功能
- Pytest学习笔记5——Allure测试报告用例详细描述
- Pytest学习笔记6——自定义用例顺序
- pytest学习和使用11-Pytest如何使用自定义标记mark?
- pytest学习和使用12-Unittest和Pytest参数化详解
- pytest学习和使用16-HTML报告如何生成?(pytest-html)
- pytest学习和使用25-当看到allure的动态生成标题和描述的特性时,直言简直太灵活了(allure.dynamic使用)