forked from EverythingWillFlow/lagou05
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_cal.py
48 lines (39 loc) · 1.57 KB
/
test_cal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import pytest
from test_param_yaml import get_datas
from pythoncode.calculator import Calculator
class TestCalc:
def setup_class(self):
print("开始测试TestCalc")
# 实例化类,生成类的对象
self.calc = Calculator()
def teardown_class(self):
print("TestCalc测试结束")
def setup_method(self):
print("\n计算开始")
def teardown_method(self):
print("\n计算结束")
# 使用参数化
# @pytest.mark.parametrize("a,b,expect",[(3,5,8),(-1,-2,-3),(10000,10000,20000)])
@pytest.mark.parametrize("a,b,expect", get_datas()[0])
# 测试add函数
def test_add(self, a, b, expect):
# 调用add函数,返回的结果保存在result里面
result = self.calc.add(a, b)
# 判断result结果是否等于期望的值
print(str(a) + " + " + str(b) + " = " + str(result))
assert result == expect
@pytest.mark.parametrize('a,b,expect', get_datas()[0])
def test_sub(self, a, b, expect):
result = self.calc.sub(a, b)
print(str(a) + " - " + str(b) + " = " + str(result))
assert result == expect
@pytest.mark.parametrize("a,b,expect", get_datas()[0])
def test_mul(self, a, b, expect):
result = self.calc.mul(a, b)
print(str(a) + " * " + str(b) + " = " + str(result))
assert result == expect
@pytest.mark.parametrize('a,b,expect', get_datas()[0])
def test_div(self, a, b, expect):
result = self.calc.div(a, b)
print(str(a) + " / " + str(b) + " = " + str(result))
assert result == expect