pytest框架

pytest框架

单元测试框架
测试用例的skip,xfail,自动失败重试
支持第三方插件,alluer测试报告,xdist多cpu分发
Jenkins集成

测试用例的识别与运行

测试文件:test_.py ,test.py
用例识别:
类 Test 没有含有init函数,认为有特殊功能的类
方法 test
*
不在class类中的,test_*
pytest也可以执行unittest框架写的用例方法
pytest 解释器
python解释器,需要添加入口函数 main

"""
@Time   :2021/11/1 12:42
@Author :Wesley
@File   :test_a.PY
"""
import pytest


def inc(x):
    return x + 1


def test_answer():
    assert inc(4) == 5


# 参数化
@pytest.mark.parametrize('a, b', [
    (1, 2),
    (10, 20),
    ('a', 'a1'),
    (3, 4),
    (5, 6)
])
def test_answer1(a, b):
    assert inc(a) == b




@pytest.fixture()
def login():
    username = 'wesley'
    return username


class TestDemo:
    # 调用fixture的方法
    def test_a(self, login):
        print(f'a    username = {login}')

    def test_b(self):
        print('b')

    # 没有test,不执行
    def c(self):
        print('c')

    def test_c(self):
        print('c')

# 使用python解释器进行执行
if __name__ == '__main__':
    pytest.main(['test_a.py::TestDemo', '-v'])


pytest - k test_b - v
# collected 4 items / 3 deselected / 1 selected
pytest - k 'test_a or test_b' - v
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值