实战干货,pytest自动化测试-Git中的测试用例运行(详细)

本文介绍了如何使用pytest-picked插件结合git来运行未提交到仓库的自动化测试用例。通过git status查看状态,pytest --picked运行修改但未提交的测试,使用--mode参数可以选择不同模式,如unstaged或branch,针对性地运行特定状态的测试用例。
摘要由CSDN通过智能技术生成


前言

我们每天写完自动化用例后都会提交到 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

–picked 参数

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

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

>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 运行用例

Changed test files
>pytest --picked

... 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 --
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值