• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

博客园    首页    新随笔    联系   管理    订阅  订阅
使用pytest-dependency解决用例间的依赖问题

使用场景:测试B仅在测试A成功通过后方能有效进行。比如购物网站,只有登录后才可以提交订单

意思是:使用该插件可以标记一个test作为其他test的依赖,当依赖项执行失败时,那些依赖它的test将会被跳过。

安装:pytest-dependency

pip install pytest-dependency

使用:

import pytest

@pytest.mark.dependency()
def test_01(test):
    assert False

@pytest.mark.dependency(depends=["test_01"])
def test_02(test):
    print("执行测试2")

看下结果:

test_01是test_02的依赖,故而test_01失败后,test_02被跳过

结论:

1、首先安装这个插件,

2、使用方法就是用 @pytest.mark.dependency()对所依赖的方法进行标记,使用@pytest.mark.dependency(depends=["test_name"])引用依赖。

posted on 2022-04-18 15:21  搁浅小夕  阅读(334)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3