随笔分类 - pytest
摘要:参考:https://www.jianshu.com/p/15594044ab27 pip install mock pip install pytest-mock (相当于mock的升级版) 举例: # 文件路径:common/mock_demo.py import requests def mo
阅读全文
摘要:先介绍几个概念: 回调函数:通俗讲是说把一个函数作为参数传给另一个函数,第一个函数称为回调函数 def computer(a, b, func): return func(a, b) def max(a, b): return [a, b][a < b] # 意思是如果a<b,则返回a,否则返回b
阅读全文
摘要:方式一: 在命令行执行: 方式二: 将命令写到文件中,运行文件
阅读全文
摘要:1.一个用例中想要写多个断言 现状:如果用assert的话,第一个assert失败后,后面的代码就不执行了 优化:想要前一个断言失败后后续断言继续执行的话,需要安装插件 pip install pytest-assume 代码实例:后续补充 2.测试用例的执行顺序 现状:文件名称 按 ASCII 码
阅读全文
摘要:ruamel.yaml官方文档:http://yaml.readthedocs.io 1.安装 pip install ruamel.yaml 第一次使用pip install ruamel.yml我没有安装成功,有报错,然后我通过https://www.lfd.uci.edu/~gohlke/py
阅读全文
摘要:注意Jenkins所在服务器要事先安装如下两个模块 pip install pytest (python的第三方单元测试框架)pip install allure-pytest (用于连接pytest和allure,这一步会安装allure-pytest和allure-python-commons包
阅读全文
摘要:1.pytest.ini的放置位置:一般放在项目工程的根目录(即当前项目的顶级文件夹下) 2.pytest.ini的作用:指定pytest的运行方式(在cmd输入pytest后,会读取pytest.ini中的配置信息,按指定的方式去运行) 3.cmd下使用 pytest -h 命令查看pytest.
阅读全文
摘要:import pytest# 使用mark标记 带参数的fixture 中的某些参数枚举值@pytest.fixture(params=[0, 1, pytest.param(2, marks=pytest.mark.skip)])def data_set(request): return requ
阅读全文
摘要:项目源码可以访问我的GitHub获取(页面右上角有地址) 思路如下 1.先使用session = requests.session(),session.post调用登录接口,return出session(保持登录状态) # -*- coding: utf-8 -*- # @Time : 2019/6
阅读全文
摘要:现象: fixture写在conftest.py中,测试用例写在测试文件中,在测试文件中ctrl+鼠标右键无法查看fixture源码 解决办法:pycharm中设置项目默认测试执行器为pytest 之后在测试文件中ctrl+鼠标左键即可查看fixture源码 注意:如果按上述操作后还无法解决的话,请
阅读全文
摘要:skip(无条件跳过测试用例)与skipif(有条件跳过测试用例) xfail skip/xfail with parametrize
阅读全文
摘要:一 环境搭建与使用demo 二 allure自定义设置 三jenkins+python+allure持续集成 一 环境搭建与使用demo 环境信息:python3.6.5 pytest5.1.2 allure2.13.0 allure-pytest2.8.5 allure的官方教程https://d
阅读全文
摘要:现象: 采用如下方式可将其正确显示为中文 附:unicode与utf8的关系:https://www.cnblogs.com/liudi2017/articles/9418465.html
阅读全文
摘要:fixture的作用:作用类似unittest中setup/teardown,它的优势是可以跨文件共享 fixture的格式:在普通函数上加上装饰器@pytest.fixture(),且函数名不能以test_开头,目的是与测试用例做区分 一 fixture的三种调用方式 1.在测试用例中 直接把fi
阅读全文
摘要:1.pytest -h 查看pytest常用命令 E:\myproj\pytest_demo>pytest -h usage: pytest [options] [file_or_dir] [file_or_dir] [...] positional arguments: file_or_dir g
阅读全文
摘要:pytest是python的一种单元测试框架(非自带,需要安装),与python自带的unitest测试框架相比,使用起来更加简洁、效率更高。总之,一句话,pytest优于unitest。 1.安装pytest (其中-U 指升级原来已经安装的包)查看安装版本 查看安装版本 pip show pyt
阅读全文
摘要:pytest收集测试用例规则 测试文件以test_开头(以_test结尾也可以) 测试类以Test开头,并且不能带有 init 方法 测试函数以test_开头(以_test结尾也可以) pytest执行测试用例规则 在命令行执行 1.运行某个目录下所有用例 pytest 目录名/ 2.运行某一个py
阅读全文

浙公网安备 33010602011771号