pytest报错_git代码提交流程

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


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报错_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% ██████████
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

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

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


相关推荐

  • 正确解决 Invalid module format[通俗易懂]

    正确解决 Invalid module format[通俗易懂]原言 http://blog.csdn.net/dreamtdp/article/details/8036419实现 功能:在PC的LINUX实现驱动测试,不用在2440上测试解决insmod:errorinserting’hello.ko’:-1Invalidmoduleformat第一次写Linux驱动,环境搭建了好久,第一次可能是由于GCC的版本问题,编译

    2022年8月28日
  • 用js来实现那些数据结构15(图01)[通俗易懂]

    其实在上一篇介绍树结构的时候,已经有了一些算法的相关内容介入。而在图这种数据结构下,会有更多有关图的算法,比如广度优先搜索,深度优先搜索最短路径算法等等。这是我们要介绍的最后一个数据结构。同时也是本系

    2022年3月25日
  • 华为数通hcie_通融理赔后需要签协议吗

    华为数通hcie_通融理赔后需要签协议吗Internet组管理协议称为IGMP协议(InternetGroupManagementProtocol),是因特网协议家族中的一个组播协议。该协议运行在主机和组播路由器之间。IGMP包含了IGMPv1、IGMPv2、IGMPv3三个版本,目前正处于由IGMPv2向IGMPv3的过渡阶段。本篇将按照IGMP基本原理、IGMP三个版本、IGMPSnooping几部分对IGMP协议进行介绍。

    2022年9月14日
  • 图论-树的最大路

    图论-树的最大路

    2021年11月29日
  • stacking的实现-mxtend库「建议收藏」

    TableofContents关于Stacked的实现库-mlxtend的学习StackingClassifier例子1简单实现stacking例子2sub-model的输出是probabilities例子3结合GridSearch列子4-针对不同整体选用不同模型StackingCVClassifier例子1简单stackingCV分类例子2sub-model的输出是prob…

    2022年4月8日
  • 5500xt挖矿性能_amd挖矿算力

    5500xt挖矿性能_amd挖矿算力[md]![ffb89a43db94f4c8.jpg](data/attachment/forum/202008/10/170713rl88j1555551tr86.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/300″ffb89a43db94f4c8.jpg”)测试系统:windows10测试显卡:蓝宝石(Sapphire)RX5600…

    2022年8月31日

发表回复

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

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