zoukankan      html  css  js  c++  java
  • pytest控制函数运行函数

    使用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
    

      

  • 相关阅读:
    JAVA日报
    JAVA日报
    JAVA日报
    论文爬取(四)
    论文爬取(三)
    论文爬取(二)
    剑指 Offer 59
    剑指 Offer 58
    剑指 Offer 58
    剑指 Offer 57
  • 原文地址:https://www.cnblogs.com/chongyou/p/12632399.html
Copyright © 2011-2022 走看看