Pytest(17)运行未提交的git(pytest-picked)

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

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

前言

我们每天写完自动化用例后都会提交到 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 文件
    Pytest(17)运行未提交的git(pytest-picked)
    如果选择是,文件会变绿色,也就是 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% ██████████
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/165677.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • goland 2102激活(JetBrains全家桶)2022.01.26[通俗易懂]

    (goland 2102激活)最近有小伙伴私信我,问我这边有没有免费的intellijIdea的激活码,然后我将全栈君台教程分享给他了。激活成功之后他一直表示感谢,哈哈~https://javaforall.net/100143.htmlIntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,上面是详细链接哦~1TCF…

    2022年3月31日
    122
  • 西班牙语欧盟语言标准c1,西班牙语级别如何划分?

    西班牙语欧盟语言标准c1,西班牙语级别如何划分?西班牙语根据欧洲共同语言参考标准分为:A1,A2,B1,B2,C1,C2六个级别。A1,A2为基础入门级别,B1,B2为高级进阶级别,C1,C2为流利进阶级别。《欧洲语言学习统一标准》(Cadreeuropéencommunderéférencepourleslangues),简称”欧标”。是欧洲议会在2001年11月通过的一套建议标准,为欧洲语言在评量架构和教学指…

    2022年6月7日
    58
  • onshow和onload区别

    onshow和onload区别onshow在每次打开页面都会加载数据,可以用于数据在需要刷新的环境下onload只是在第一次进入页面会刷新数据,从二级页面回来不会重新加载数据

    2022年6月17日
    49
  • 收集的84个网站源码分享

    收集的84个网站源码分享2019帝国CMS7.5仿《ITBear科技资讯》源码——————链接:https://pan.baidu.com/s/1dIOJ16pu4eRiPh7feAPQ0A提取码:svr9YMYS009强大专业的x站——————链接:https://pan.baidu.com/s/1FHWIq6VLgndBiyCXwrkHUA提取码:gvuw粉色小说网站——————链接:https://pan.baidu.com/s/1sm

    2022年6月14日
    63
  • (一)Rxjava2+Retrofit完美封装

    (一)Rxjava2+Retrofit完美封装本篇文章已授权微信公众号 guolin blog 郭霖 独家发布要说 2016 年最火的 Android 技术是什么 毫无疑问肯定是 RxJava Retrofit Mvp 现如今 2017 年也已经过了快一半了 相信做 android 开发的小伙伴对 RxJava 和 Retrofit 也不再陌生 即使没有刻意的去学习过 也应该对 RxJava 和 Retrofit 有个一知半解 去年的时候学习了 Rxjava 和 Retr

    2025年11月20日
    2
  • nodejs创建vue项目_vue数据不渲染

    nodejs创建vue项目_vue数据不渲染tl;dr:GivenaVueJSVNodeobject,howdoIgettheHTMLelementthatwouldbegeneratedifitwererendered?e.g.:>temp1VNode{tag:”h1″,data:undefined,children:Array(1),text:undefined,elm:…

    2025年6月3日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号