首页 > 其他 > 详细

pytest控制函数运行函数

时间:2020-04-04 17:35:07      阅读:134      评论:0      收藏:0      [点我收藏+]

使用pytest控制函数运行的函数 需要使用

(1)使用 @pytest.mark.run(order=x) 标记被测试函数

(2)运行的顺序由order传入的参数决定;(order从小到大的顺序执行)

import pytest

class Calc(object):
    @classmethod
    def add(cls, x, y, *d):
        # 加法计算
        result = x + y
        for i in d:
            result += i
        return result

    @classmethod
    def sub(cls, x, y, *d):
        # 减法计算
        result = x - y
        for i in d:
            result -= i
        return result

    @classmethod
    def mul(cls, x, y, *d):
        # 乘法计算
        result = x * y
        for i in d:
            result *= i
        return result

    @staticmethod
    def div(x, y, *d):
        # 除法计算
        if y != 0:
            result = x / y
        else:
            return -1
        for i in d:
            if i != 0:
                result /= i
            else:
                return -1
        return result

@pytest.mark.run(order=2)
def test_add():
    assert Calc.add(1, 2, 3) == 6

@pytest.mark.run(order=3)
def test_add2():
    assert Calc.add(1, 2, 3) == 6


@pytest.mark.run(order=1)
def test_sub():
    assert Calc.sub(100, 20, 30) == 50

  技术分享图片

 

pytest控制函数运行函数

原文:https://www.cnblogs.com/chongyou/p/12632399.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!