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

