前言

我们每天写完自动化用例后都会提交到 git 仓库,随着用例的增多,为了保证仓库代码的干净,当有用例新增的时候,我们希望只运行新增的未提交 git 仓库的用例。pytest-picked 插件可以实现只运行未提交到git仓库的代码。

安装

pip3 install pytest-picked

使用示例

$ pytest --picked

$ pytest --picked=first

$ pytest --picked --mode=branch

$ pytest --picked --mode=unstaged  # default

$ pytest --picked --mode=branch --parent-branch=main # if your parent branch differs from "master"

--picked 参数

我们在已提交过 git 仓库的用例里面新增了 1 个文件 test_new.py

cd到项目根目录,使用git status查看当前分支状态

> git status

On branch master
Your branch is up to date with 'origin/master'. Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: case/test_new.py Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: case/test_new.py

可以看到有1个文件,使用 pytest --picked 运行用例

Changed test files... 1. ['case/test_new.py']
collecting ...
case/test_new.py ✓ 100% ██████████ Results (0.04s):
1 passed

--picked=first

首先运行修改后的测试文件中的测试,然后运行所有未修改的测试

--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 查看当前分支的状态,此时会看到 case/test_new2.py 是 Untracked files
> git status

Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: case/test_new.py Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: case/test_new.py Untracked files:
(use "git add <file>..." to include in what will be committed)
case/test_new2.py

运行 pytest --picked 会默认执行所有的 Untracked 文件和 not staged 文件,默认是--mode=unstaged。

collecting ...
case/test_new2.py::test_2 ✓ 50% █████
case/test_new.py::test_1 ✓ 100% ██████████

如果我们只需运行当前分支上已经被暂存,但尚未提交的文件(不包含 Untracked files)

运行 pytest --picked --mode=branch, 运行分支上已经被暂存但尚未提交的代码

(pytest_env) ➜  apitest git:(master) ✗ pytest --picked --mode=branch

Changed test files... 1. ['case/test_new.py']
Changed test folders... 0. []
collecting ...
case/test_new.py::test_1 ✓ 100% ██████████

Pytest(17)运行未提交的git(pytest-picked)的更多相关文章

  1. pytest文档59-运行未提交git的用例(pytest-picked)

    前言 我们每天写完自动化用例后都会提交到 git 仓库,随着用例的增多,为了保证仓库代码的干净,当有用例新增的时候,我们希望只运行新增的未提交 git 仓库的用例. pytest-picked 插件可 ...

  2. 使用git恢复未提交的误删数据

    不小心将项目中一个文件夹删除还未提交,或者已经提交, 此时想要恢复数据该怎么办? 答案是git reflog,使用git reflog命令可以帮助恢复git误操作,进行数据恢复. 操作过程: 打开终端 ...

  3. pycharm中不以pytest方式运行,以普通方式运行的方法

    问题: 在调试一个很简单的代码时无法输出结果,运行结果如下形式: 出现以上情况,主要是因为在运行时是以pytest方式运行的,要换回以普通方式去运行. 问题解决: 首先是红色圈圈里的白色三角形. 然后 ...

  4. pytest.2.运行多个文件

    From: http://www.testclass.net/pytest/multiple_tests/ 背景 在现实的测试活动中,我们经常会定义多个用例文件,用来实现业务逻辑或其他逻辑上用例的物理 ...

  5. jenkins+pytest+ allure运行多个py文件测试用例

    jenkins的pytest运行多个py文件,导出allure报告方法,只需改下job的配置中的构建即可(pytest会运行指定文件下的所有test开头的py文件),如下:              ...

  6. 如何将本地未提交的更改合并到另一个Git分支?

    如何在Git中执行以下操作? 我当前的分支是branch1,我做了一些本地更改. 但是,我现在意识到我实际上是要将这些更改应用于branch2. 有没有办法应用/合并这些更改,以便它们成为branch ...

  7. pytest-pyppeteer:在pytest中运行pyppeteer

    pytest-pyppeteer pytest-pyppeteer是我写的一个 pytest 插件,支持在 pytest 中运行pyppeteer,起因是为了解决工作中的一个测试需求,现在将其开源并做 ...

  8. 1git命令的使用,查看git仓库状态,添加文件到git跟踪,git提交,查看git分支,查看git仓库日志信息,切换git分支,解决git分支合并后出现冲突的问题

    1新建一个存储git的文件夹,命令是: toto@toto-K45VD:~$ mkdir gitfolder 2初始化一个git仓库,命令是: toto@toto-K45VD:~$cd gitfold ...

  9. SQL Server 中的事务与事务隔离级别以及如何理解脏读, 未提交读,不可重复读和幻读产生的过程和原因

    原本打算写有关 SSIS Package 中的事务控制过程的,但是发现很多基本的概念还是需要有 SQL Server 事务和事务的隔离级别做基础铺垫.所以花了点时间,把 SQL Server 数据库中 ...

随机推荐

  1. Spring 抽象的缓存包 spring-cache

    项目实战 用户信息查询接口中,使用@Cacheable注解  绑定相关信息接口中,使用@CachePut更新用户信息到缓存 更新用户信息接口中,使用@CacheEvict删除缓存信息 使用步骤 添加依 ...

  2. 冷饭新炒:理解Redisson中分布式锁的实现

    前提 在很早很早之前,写过一篇文章介绍过Redis中的red lock的实现,但是在生产环境中,笔者所负责的项目使用的分布式锁组件一直是Redisson.Redisson是具备多种内存数据网格特性的基 ...

  3. 【Java基础】数组和算法

    数组和算法 查找算法 线性查找 ... 二分查找 二分查找要求数据结构是有序的. package com.parzulpan.java.ch03; /** * @Author : parzulpan ...

  4. Flutter 基础组件:按钮

    前言 Material组件库中提供了多种按钮组件如RaisedButton.FlatButton.OutlineButton等,它们都是直接或间接对RawMaterialButton组件的包装定制,所 ...

  5. selenium自动化 | 通过获取cookies登录

    >>>登录百度<<<#获取登录成功后的cookies def get_cookies(): driver.get(bd_url) driver.implicitly ...

  6. ps -eo 用户自定义格式显示

    [root@ma ~]# ps -eo pid,ucomm|head -3 PID COMMAND 1 init 2 kthreadd[root@ma ~]# ps axu|head -3USER P ...

  7. 【Linux】cp命令的各种妙用

    CP 功能: 复制文件或目录 说明: cp指令用于复制文件或目录,如同时指定两个以上的文件或目录,且最后的目的地是一个已经存在的目录,则它会把前面指定的所有文件或目录复制到此目录中.若同时指定多个文件 ...

  8. 【Oracle】Oracle SQL的优化软件

    对于SQL开发人员和DBA来说,根据业务需求写出一条正确的SQL很容易.但是SQL的执行性能怎么样呢?能优化一下跑得更快吗?如果不是资深  DBA,估计很多人都没有信心. 幸运的是,自动化优化工具可以 ...

  9. 【ORA】ORA-00257 archiver error. 错误的处理方法

    今天连接数据库,结果报错,ora-00257查看 [oracle@exam oracle]$ oerr ora 00257 00257, 00000, "archiver error. Co ...

  10. LeetCode783. 二叉搜索树节点最小距离

    题目 和LeetCode530没什么区别 1 class Solution { 2 public: 3 vector<int>ans; 4 int minDiffInBST(TreeNod ...