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
作者:做梦的人(小姐姐) 出处:https://www.cnblogs.com/chongyou/ 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。 如果文中有什么错误,欢迎指出。以免更多的人被误导。 微信号:18582559217 |