pytest文档59-运行未提交git的用例(pytest-picked)
前言
我们每天写完自动化用例后都会提交到 git 仓库,随着用例的增多,为了保证仓库代码的干净,当有用例新增的时候,我们希望只运行新增的未提交 git 仓库的用例。 pytest-picked 插件可以实现只运行未提交到git仓库的代码。
pytest-picked
使用命令行安装
pip install pytest-picked
可使用参数
picked:
--picked=[{only,first}]
Run the tests related to the changed files either on their own, or first
--mode=PICKED_MODE Options: unstaged, branch
使用示例:
$ pytest --picked
$ pytest --picked=first
$ pytest --picked --mode=branch
$ pytest --picked --mode=unstaged # default
github仓库地址https://github.com/anapaulagomes/pytest-picked
—picked 参数
我们在已提交过 git 仓库的用例里面新增了 2 个文件 test_new.py 和 test_new_2.py
cd到项目根目录,使用 git status
查看当前分支状态
# 作者-上海悠悠 QQ交流群:717225969
# blog地址 https://www.cnblogs.com/yoyoketang/
>git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: pytest_demo/test_new.py
new file: pytest_demo/test_new_2.py
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: pytest_demo/test_new.py
modified: pytest_demo/test_new_2.py
可以看到有2个文件,使用 pytest --picked
运行用例
>pytest --picked
Changed test files... 2. ['pytest_demo/test_new.py', 'pytest_demo/test_new_2.py']
Changed test folders... 0. []
================================================= test session starts =================================================
platform win32 -- Python 3.6.6, pytest-6.0.2, py-1.9.0, pluggy-0.13.1
Test order randomisation NOT enabled. Enable with --random-order or --random-order-bucket=<bucket_type>
rootdir: D:democodexuexi_pytest
collected 4 items
pytest_demotest_new.py .. [ 50%]
pytest_demotest_new_2.py .. [100%]
================================================== 4 passed in 0.20s ==================================================
所有测试都将从已修改但尚未提交的文件和文件夹中运行。
—picked=first
首先运行修改后的测试文件中的测试,然后运行所有未修改的测试
>pytest --picked=first
================================================= test session starts =================================================
platform win32 -- Python 3.6.6, pytest-6.0.2, py-1.9.0, pluggy-0.13.1
rootdir: D:democodexuexi_pytest
collected 11 items
pytest_demotest_new.py .. [ 18%]
pytest_demotest_new_2.py .. [ 36%]
pytest_demotest_b.py ...... [ 90%]
pytest_demotest_c.py . [100%]
================================================= 11 passed in 0.10s ==================================================
—mode=PICKED_MODE
--mode
有2个参数可选 unstaged, branch, 默认是--mode=unstaged
git 文件的2个状态
- untrack 没加到git里面的新文件
- unstaged staged: 暂存状态, unstage就是未暂存状态,也就是没git add 过的文件
先弄清楚什么是 untrack 状态,当我们 pycharm 打开 git 项目,新增一个文件的时候,会弹出询问框:是否加到 git 文件
如果选择是,文件会变绿色,也就是 unstage 状态(没git add 过);选择否,那就是一个新文件,未被加到当前分支的 git 目录里面,文件颜色是棕色。
git status
查看当前分支的状态,此时会看到 pytest_demo/test_3.py 是 Untracked files
# 作者-上海悠悠 QQ交流群:717225969
# blog地址 https://www.cnblogs.com/yoyoketang/
>git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: pytest_demo/test_new.py
new file: pytest_demo/test_new_2.py
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: pytest_demo/test_new.py
modified: pytest_demo/test_new_2.py
Untracked files:
(use "git add <file>..." to include in what will be committed)
.idea/
pytest_demo/__pycache__/
pytest_demo/test_3.py
运行 pytest --picked
会默认执行所有的 Untracked 文件和 not staged 文件,默认是--mode=unstaged
。
>pytest --picked
Changed test files... 3. ['pytest_demo/test_new.py', 'pytest_demo/test_new_2.py', 'pytest_demo/test_3.py']
Changed test folders... 2. ['.idea/', 'pytest_demo/__pycache__/']
================================================= test session starts =================================================
platform win32 -- Python 3.6.6, pytest-6.0.2, py-1.9.0, pluggy-0.13.1
collected 5 items
pytest_demotest_new.py .. [ 40%]
pytest_demotest_new_2.py .. [ 80%]
pytest_demotest_3.py . [100%]
================================================== 5 passed in 0.06s ==================================================
如果我们只需运行当前分支上已经被暂存,但尚未提交的文件(不包含 Untracked files),使用 git diff 查看分支代码的差异
>git diff --name-only master
pytest_demo/test_new.py
pytest_demo/test_new_2.py
运行 pytest --picked --mode=branch
, 运行分支上已经被暂存但尚未提交的代码
>pytest --picked --mode=branch
Changed test files... 2. ['pytest_demo/test_new.py', 'pytest_demo/test_new_2.py']
Changed test folders... 0. []
================================================= test session starts =================================================
platform win32 -- Python 3.6.6, pytest-6.0.2, py-1.9.0, pluggy-0.13.1
collected 4 items
pytest_demotest_new.py .. [ 50%]
pytest_demotest_new_2.py .. [100%]
================================================== 4 passed in 0.04s ==================================================
- 左手用R右手Python系列之——noSQL基础与mongodb入门
- 左手用R右手Python系列之——数据框与apply向量运算
- 左手用R右手Python系列之——迭代器与迭代对象
- 【关关的刷题日记61】Leetcode 102. Binary Tree Level Order Traversal
- 【关关的刷题日记62】Leetcode 104. Maximum Depth of Binary Tree
- DataAnnotations - InverseProperty Attribute:
- 【关关的刷题日记63】Leetcode 111 Minimum Depth of Binary Tree
- Configure Many-to-Many relationship:
- 【关关的刷题日记64】Leetcode 110 Balanced Binary Tree
- 左手用R右手Python系列之——json序列化与反序列化
- 【干货】GAN调研:多极扩展(跨域和条件的GAN扩展模型调研)
- 【干货】TensorFlow实战——图像分类神经网络模型
- HTML5手机APP开发入(5)
- 这种自带黑科技的R包,请给我来一打
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- iOS动态View的探索
- 安卓开发的瑞士军刀“Retrofit2框架”
- R语言中的广义线性模型(GLM)和广义相加模型(GAM):多元(平滑)回归分析保险资金投资组合信用风险敞口
- 来玩 TencentOS tiny 物联网终端操作系统
- LeetCode | 66.加一
- PNN:Product-based Neural Networks for User Response Prediction
- Redis | Redis Pub/Sub相关命令
- nginx upstream header过大是啥情况
- 8个写JavaScript代码的小技巧
- .NET Core中间件与依赖注入的一些思考
- 如何审计MySQL 8.0中的分类数据查询?
- 聊一个 GitHub 上开源的 RBAC 权限管理系统,很6!
- Spring AOP,应该不会有比这更详细的介绍了!
- 我又发现 Spring Security 中一个小秘密!
- OpenCV的实用图像处理操作案例分享