目录

1、pytest-picked(运行未提交的git用例)

1.1、安装

1.2、参数

1.3、用法

1.4、示例

2、pytest-lazy-fixture(在pytest.mark.parametrize中使用fixture)

2.1、安装

2.2、示例


1、pytest-picked(运行未提交的git用例)

自动化测试用例一般编写完后且又执行通过,都会提交到 git 仓库里。但是每次新增用例后,希望只执行未提交到 git 仓库里的用例。

pytest-picked 插件可以实现只执行未提交到 git 仓库里的测试用例。

1.1、安装

在命令行中运行以下命令进行安装:

pip install pytest-picked

或者(使用国内的豆瓣源,数据会定期同步国外官网,速度快。)

pip install pytest-picked -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

1.2、参数

  • --picked=[{only,first}] 单独或首先运行与更改的文件相关的测试

  • --mode=PICKED_MODE    Options: unstaged, branch

  • --parent-branch=PARENT_BRANCH 回购的主要分支(master、main、trunk等)

1.3、用法

pytest --pickedpytest --picked=firstpytest --picked --mode=branchpytest --picked --mode=unstaged # 默认pytest --picked --mode=branch --parent-branch=main # 如果你的父分支与主分支"master"不同

1.4、示例

以gitlab为例,首先要创建gitlab账号

访问官网并注册账号

https://gitlab.com/

使用git前,要先安装git

访问官网下载并安装即可

https://git-scm.com/

创建项目,项目目录结构:

创建test_case1.py文件

脚本代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
微信公众号:AllTests软件测试
"""class TestDemo():def test_case1(self):print("执行用例1")def test_case2(self):print("执行用例2")def test_case3(self):print("执行用例3")

创建test_case2.py文件

脚本代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
微信公众号:AllTests软件测试
"""class TestClass():def test_case4(self):print("执行用例4")def test_case5(self):print("执行用例5")def test_case6(self):print("执行用例6")

在gitlab上创建相关项目,例如My_Demo

PyCharm上创建本地git仓库

配置gitlab上所创建的项目(My_Demo)地址

提交

push到远程仓库里

已将项目同步到gitlab上

之后再新增2个文件,添加用例

创建test_case3.py文件

脚本代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
微信公众号:AllTests软件测试
"""class TestAdd1():def test_case7(self):print("执行用例7")def test_case8(self):print("执行用例8")def test_case9(self):print("执行用例9")

创建test_case4.py文件

脚本代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
微信公众号:AllTests软件测试
"""class TestAdd2():def test_case10(self):print("执行用例10")def test_case11(self):print("执行用例11")def test_case12(self):print("执行用例12")

创建完成后的目录结构

命令行跳转到项目的根目录,输入命令查看当前分支状态

git status

新增的2个文件没有提交到git仓库里

1、使用参数(--picked)

命令行输入执行命令

pytest --picked

运行结果:只运行新增的2个文件用例

2、使用参数(--picked=first)

命令行输入执行命令

pytest --picked=first

运行结果:首先运行修改后的测试文件,之后运行所有未修改的测试文件。

2、pytest-lazy-fixture(在pytest.mark.parametrize中使用fixture)

pytest-lazy-fixture 插件,解决在测试用例中使用 @pytest.mark.parametrize 参数化时调用 fixture。

2.1、安装

在命令行中运行以下命令进行安装:

pip install pytest-lazy-fixture

或者(使用国内的豆瓣源,数据会定期同步国外官网,速度快。)

pip install pytest-lazy-fixture -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

2.2、示例

示例一:@pytest.mark.parametrize 参数化

创建test_lazy_fixture.py文件

脚本代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
微信公众号:AllTests软件测试
"""import pytest@pytest.fixture(params=["admin", "123456"])
def my_fixture(request):return request.param@pytest.mark.parametrize("param1, param2", [("login", pytest.lazy_fixture("my_fixture"))])
def test_case(param1, param2):print("\n参数param1:" + param1)print("\n参数param2:" + param2)assert param2 in ["admin", "123456"]

打开命令行,输入执行命令:

pytest -s -v test_lazy_fixture.py

运行结果:

示例二:@pytest.fixture 参数化

创建test_lazy_fixture2.py文件

脚本代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
微信公众号:AllTests软件测试
"""import pytest@pytest.fixture
def my_fixture_1():one = "admin"return one@pytest.fixture
def my_fixture_2():two = "123456"return two@pytest.fixture(params=[pytest.lazy_fixture("my_fixture_1"), pytest.lazy_fixture("my_fixture_2")])
def my_fixture_all(request):return request.paramdef test_case(my_fixture_all):print("\n参数:" + my_fixture_all)assert my_fixture_all in ["admin", "123456"]

打开命令行,输入执行命令:

pytest -s -v test_lazy_fixture2.py

运行结果:

Python测试框架pytest(23)插件 - pytest-picked、pytest-lazy-fixture相关推荐

  1. python测试框架untest_Python测试框架之unittest和pytest

    目前搜狗商城接口测试框架用的是unittest+HTMLTestRunner,case数有1097条,目前运行一次自动化测试,时长约为30分钟,期望控制在10分钟或者更短的时间内.近期打算重新优化框架 ...

  2. Python测试框架之pytest详解

    目录 前言 1.pytest安装 2.Pytest的setup和teardown函数 3.Pytest配置文件 4 Pytest常用插件 4.1 前置条件: 4.2 Pytest测试报告 5.pyte ...

  3. Python测试框架Pytest的基础入门

    Pytest简介 Pytest is a mature full-featured Python testing tool that helps you write better programs.T ...

  4. 全功能Python测试框架:pytest

    python通用测试框架大多数人用的是unittest+HTMLTestRunner,这段时间看到了pytest文档,发现这个框架和丰富的plugins很好用,所以来学习下pytest. pytest ...

  5. Python测试框架pytest(05)fixture - error和failed、fixture实例化、多个fixture

    Python测试框架pytest系列可以查看下列 Python测试框架pytest(01)简介.安装.快速入门_编程简单学的博客-CSDN博客 Python测试框架pytest(02)PyCharm设 ...

  6. Python测试框架pytest(04)fixture - 测试用例调用fixture、fixture传递测试数据

    Python测试框架pytest系列可以查看下列 Python测试框架pytest(01)简介.安装.快速入门_编程简单学的博客-CSDN博客 Python测试框架pytest(02)PyCharm设 ...

  7. Python测试框架pytest(03)setup和teardown

    Python测试框架pytest系列可以查看下列 Python测试框架pytest(01)简介.安装.快速入门_编程简单学的博客-CSDN博客 ​​​​​​Python测试框架pytest(02)Py ...

  8. gtest测试框架使用详解_【python】新手小白必看,教你如何使用全功能Python测试框架 - python秋枫...

    大家好,我是在升职加薪道路上越奋斗头发越少的阿茅. 今天来跟想入门还徘徊在门外的小白们聊一聊 1.安装和简单使用 2.配置文件 3.断言 一. 第1步 (安装和简单使用) pytest是一个非常成熟的 ...

  9. Python测试框架pytest(22)插件 - pytest-xdist(分布式执行)

    目录 1.安装 2.示例 3.原理和流程 4.解决:多进程运行次数 当测试用例非常多的时候,一条条按顺序执行测试用例,是很浪费测试时间的.这时候就可以用到 pytest-xdist,让自动化测试用例可 ...

  10. Python测试框架pytest(01)简介、安装、快速入门

    1.简介 pytest 是成熟的功能齐全的 Python 测试工具,可帮助你编写更好的程序. pytest 是一个使构建简单和可伸缩的测试变得容易的框架.测试具有表达性和可读性,不需要样板代码.几分钟 ...

最新文章

  1. 包区别 版本_详解Linux下二进制包、源代码包、rpm包区别与联系
  2. 基于单片机的c语言倒计时程序,30秒倒计时c语言51单片机实现.doc
  3. Python IDE之Pydev: 基于Eclipse搭建python的编译环境(Eclipse+pydev)简介、安装、使用的详细攻略
  4. IntelliJ IDEA for Mac 修改项目模块的名称
  5. iPhone 14或让果粉再度“梦碎”:屏幕指纹和120Hz高刷屏都没了
  6. idea 热部署无效
  7. 系统学习NLP(二)--语音合成的计算机处理综述
  8. jQury+Ajax与C#后台交换数据
  9. 【开发工具】【i2c-tools】I2C总线调试工具(i2c-tools)的安装与使用
  10. 商品信息SKU数据库设计
  11. 现浇板用弹性计算方法_弹性楼板的计算和选择
  12. 工行u盾显示316_工行U盾无法被电脑识别(方法全集)
  13. PD虚拟机设置替代ALT+F4(关闭窗口)的快捷键的方法
  14. 需求与商业模式创新-需求2-需求基础
  15. stm32f103gd32的usb虚拟串口,打印类printer组合设备
  16. 第69天-内网安全-域横向 CobaltStrikeSPNRDP
  17. algorithm的使用
  18. 杰理-手表-AC701-watch-马达振动一次
  19. 天载配资点评指数放量下跌
  20. 阿里云服务器4核8G配置CPU性能报价表

热门文章

  1. jdk17下载与安装教程(win10),超详细
  2. idea最新Activation code
  3. css中outline,css中outline的解析(附示例)
  4. 微信支付android白屏,android 解决微信登陆白屏样式问题
  5. OJ每日一练——羞涩的答复
  6. 一首《轨迹》,再一曲《搁浅》,满满的的回忆
  7. 计算机一级经验分享,计算机一级考试经验
  8. uedit php,laravel uedit上传oss
  9. 云闪付和微信支付达成“条码支付互通”,二者支付功能有何不同?
  10. 自定义android模拟器,在模拟器上运行自定义Android ROM