随笔分类 - Pytest
Pytest框架学习
摘要:--durations用于计算每个用例执行的执行时间,并进行排序 > pytest -h --durations=N show N slowest setup/test durations (N=0 for all). --durations-min=N Minimal duration in se
阅读全文
摘要:当用命令pytest执行用例时,控制台会输出很多信息,不方便追溯问题信息,可以通过--tb命令行参数控制输入信息内容 pytest -h 查看--tb参数的使用方法 > pytest -h --tb=style traceback print mode (auto/long/short/line/n
阅读全文
摘要:获取测试用例的运行结果: #conftest.py import pytest @pytest.hookimpl(hookwrapper=True, tryfirst=True) def pytest_runtest_makereport(item, call): print(' ') # 获取钩子
阅读全文
摘要:在Pytest中,conftest.py中方法命名越复杂时,就显得难以理解,这时可以使用别名来使代码更加容易解读 只需使用fixture中的name参数即可,案例如下: #conftest.py import pytest @pytest.fixture(scope="session",name="
阅读全文
摘要:在编写脚本调试时,需要打印一些必要信息来检查脚本的执行情况,这里就要用到python的标准模块 logging 在pytest中,使用方法很简单,在pytest的配置文件中配置好信息即可 pytest.ini log_cli = 1 #代表ture 1代表执行日志显示更详细 log_cli_leve
阅读全文
摘要:import requests import pytest def pytest_addoption(parser): #添加参数到pytest.ini parser.addini('参数名', type=None, default="http://url", help='注释') # 获取 pyt
阅读全文
摘要:def pytest_terminal_summary(terminalreporter, exitstatus, config): '''收集测试结果''' # print(terminalreporter.stats) total = terminalreporter._numcollected
阅读全文
摘要:Python实现Cmultipart/form-data表单类接口请求, 需要安装插件 pip install requests-toolbelt==0.9.1 请求表单类接口,实现如下: from requests_toolbelt import MultipartEncoder from ke1
阅读全文
摘要:pytest操作数据所需模块PyMysql 安装推荐:pip install PyMysql==0.9.3 先写个方法获取到项目的根目录 # coding=utf-8 import os def root_path(): cur_path = os.path.dirname(os.path.real
阅读全文
摘要:对于一些场景需要大量数据来支撑的测试,就可以用到参数化来节省手工测试所花费的时间 pytest参数化需要用到装饰器:parametrize 用户,导入pytest模块之后,在函数上方使用,效果如下: import pytest @pytest.mark.parametrize("id,goodsco
阅读全文
摘要:对v2ex网址查看论坛节点信息的api进行测试 请求内容如下: Url:https://www.v2ex.com/api/nodes/show.json Method:GET Authentication:None 请求参数:name:节点名称 返回结果如下: { "avatar_large": "
阅读全文