import pytest
from pytest_prac.src.calculator import Calculator
class TestCal:
def teardown_class(self):
print("结束测试")
def setup(self):
print("开始计算")
def teardown(self):
print("结束计算")
@pytest.mark.P0
@pytest.mark.add
@pytest.mark.parametrize("a,b,c", [(1, 1, 2), (-0.01, 0.02, 0.01), (10, 0.02, 10.02)],
ids=["【正向】2个整数相加,结果计算正确",
"【正向】2个浮点数相加,结果计算正确",
"【正向】整数与浮点数相加,结果计算正确"])
def test_add1(self, a, b, c):
"""测试相加功能P0用例"""
# 第一步:创建Calculator计算器实例对象
calc = Calculator()
assert c == calc.add(a, b)
@pytest.mark.P1
@pytest.mark.add
@pytest.mark.youxiao
@pytest.mark.parametrize("a,b,c",
[(98.99, 99, 197.99), (99, 98.99, 197.99), (-98.99, -99, -197.99), (-99, -98.99, -197.99)],
ids=["【边界】有效边界值相加,结果计算正确1", "【边界】有效边界值相加,结果计算正确2",
"【边界】有效边界值相加,结果计算正确3", "【边界】有效边界值相加,结果计算正确4"])
def test_add2(self, a, b, c):
"""测试相加功能P1用例有效参数"""
calc = Calculator()
assert c == calc.add(a, b)
@pytest.mark.P1
@pytest.mark.add
@pytest.mark.wuxiaonum
@pytest.mark.parametrize("a,b", [(99.01, 0), (-99.01, -1), (2, 99.01), (1, -99.01)],
ids=["【边界】无效边界值相加,给出提示信息1", "【边界】无效边界值相加,给出提示信息2",
"【边界】无效边界值相加,给出提示信息3", "【边界】无效边界值相加,给出提示信息4"])
def test_add3(self, a, b):
"""测试相加功能P1用例无效参数"""
calc = Calculator()
assert "参数大小超出范围" == calc.add(a, b)
# return calc.add(a,b)
#
# def get_w_s(num):
# xs = Decimal(str(num)).as_tuple()
# return abs(xs[2])
@pytest.mark.P1
@pytest.mark.add
@pytest.mark.wuxiaoqita
@pytest.mark.parametrize("a,b", [("文", 9.3), (4, "文"), ("nu", 0.2), (30, "t"), ("*&", 0.2), (21.45, "@")],
ids=["【类型】输入中文,给出提示信息1", "【类型】输入中文,给出提示信息2",
"【类型】输入英文,给出提示信息1", "【类型】输入英文,给出提示信息2",
"【类型】输入特殊字符,给出提示信息1", "【类型】输入特殊字符,给出提示信息2"])
def test_add4(self, a, b):
"""测试相加功能P1用例无效参数"""
calc = Calculator()
try:
assert "参数大小超出范围" == calc.add(a, b)
except Exception as e:
assert "参数大小超出范围" == e
# return calc.add(a, b)
@pytest.mark.P2
@pytest.mark.add
@pytest.mark.parametrize("a,b", [("", -3), (20.93, ""), (" ", 3.14), (-90, " ")],
ids=["【类型】输入为空,给出提示信息1", "【类型】输入为空,给出提示信息2",
"【类型】输入空格,给出提示信息1", "【类型】输入空格,给出提示信息2"])
def test_add5(self, a, b):
"""测试相加功能P1用例无效参数"""
calc = Calculator()
try:
assert "参数大小超出范围" == calc.add(a, b)
except Exception as e:
assert "参数大小超出范围" == e
# return calc.add(a, b)