class TestCalc: def setup(self): self.calc = Calc() @pytest.mark.parametrize('test_data', add_data.get_data("norm")) @pytest.mark.run(order=2) @allure.step("测试加法函数") def test_add_1(self,test_data): print(step1) if 'add' in step1: result = self.calc.add(test_data['a'], test_data['b']) print(test_data['a']) print(test_data['b']) print(result) assert test_data['res']-result<0.0001 @pytest.mark.parametrize('test_data', sub_data.get_data("norm")) @allure.step("测试减法函数") def test_sub_1(self, test_data): print(step1) if 'sub' in step1: result = self.calc.sub(test_data['a'], test_data['b']) print(test_data['a']) print(test_data['b']) print(result) assert test_data['res'] - result < 0.0001 @pytest.mark.parametrize('test_data', mul_data.get_data("norm")) @allure.step("测试乘法函数") def test_mul_1(self, test_data): print(step1) if 'mul' in step1: result = self.calc.mul(test_data['a'], test_data['b']) print(test_data['a']) print(test_data['b']) print(result) assert test_data['res'] - result < 0.0001 @pytest.mark.parametrize('test_data', div_data.get_data("norm")) @pytest.mark.run(order=1) @allure.step("测试除法函数") def test_div_1(self,test_data): print(step1) for step in step1: print(f"step ==== > {step}") if 'div' in step1: try: result = self.calc.div(test_data['a'], test_data['b']) print(test_data['a']) print(test_data['b']) print(result) except ZeroDivisionError: print("0不能做除数") assert test_data['res']-result<0.0001
class TestCalc(): @pytest.fixture() def test_new_calc(self): self.calc_ob = Calc() @pytest.mark.parametrize("a,b,add", yaml.safe_load(open("datas/add.yml"))) def calc_add(self, test_new_calc, a, b, add): steps_ = steps() for step in steps_: if 'add' == step: result = self.calc_ob.add(a, b) assert result == add # assert self.calc_ob.add(a,b)==sum @pytest.mark.parametrize("a,b,sub", yaml.safe_load(open("datas/sub.yml"))) def calc_sub(self, test_new_calc, a, b, sub): steps_ = steps() for step in steps_: if 'sub' == step: result = self.calc_ob.sub(a, b) if isinstance(result, str): print(result) assert "Exception" in result else: assert '%.5f' % result == '%.5f' % sub # assert self.calc_ob.add(a,b)==sum @pytest.mark.parametrize("a,b,mul", yaml.safe_load(open("datas/mul.yml"))) def calc_mul(self, test_new_calc, a, b, mul): calc_result = self.calc_ob.mul(a, b) if isinstance(calc_result, str): print(calc_result) assert "Exception" in calc_result else: assert '%.5f' % calc_result == '%.5f' % mul # @pytest.mark.skip("div") @pytest.mark.parametrize("a,b,div", yaml.safe_load(open("datas/div.yml"))) def calc_div(self, test_new_calc, a, b, div): steps_ = steps() for step in steps_: if 'div' == step: calc_result = self.calc_ob.div(a, b) if isinstance(calc_result, str): print(calc_result) assert "Exception" in calc_result else: assert '%.5f' % calc_result == '%.5f' % div
class TestCalc: def setup(self): self.calc = Calc() @pytest.mark.run(order=2) # @pytest.mark.add @pytest.mark.parametrize('a, b, expected', yaml.safe_load(open("../data/calc_add.yaml"))) def calc_add(self, a, b, expected): try: actual_result = self.calc.add(a, b) assert round(actual_result, 2) == expected except TypeError: print("请输入数字") @pytest.mark.run(order=1) # @pytest.mark.sub @pytest.mark.parametrize('a, b, expected', yaml.safe_load(open("../data/calc_sub.yaml"))) def calc_sub(self, a, b, expected): try: actual_result = self.calc.sub(a, b) assert round(actual_result, 2) == expected except TypeError: print("请输入数字") @pytest.mark.run(order=3) # @pytest.mark.div @pytest.mark.parametrize('a, b, expected', yaml.safe_load(open("../data/calc_div.yaml"))) def calc_div(self, a, b, expected): try: if b == 0: print("除数不能为0") else: actual_result = self.calc.div(a, b) assert round(actual_result, 2) == expected except TypeError: print("请输入数字") @pytest.mark.run(order=4) # @pytest.mark.div @pytest.mark.parametrize('a, b, expected', yaml.safe_load(open("../data/calc_mul.yaml"))) def calc_div(self, a, b, expected): try: actual_result = self.calc.mul(a, b) assert round(actual_result, 2) == expected except TypeError: print("请输入数字")
class TestCalc: def setup(self): self.calc = Calc() @pytest.mark.parametrize('a,b,c', [(0, 0, 0), (1, 1, 2), (-1, -1, -2)]) def test_add(self, a, b, c): result = self.calc.add(a, b) assert c == result @pytest.mark.parametrize('a,b,c', [(0, 0, 0), (1, 1, 0), (-1, -1, 0)]) def test_sub(self, a, b, c): result = self.calc.sub(a, b) assert c == result @pytest.mark.parametrize('a,b,c', [(0, 0, 0), (1, 1, 1), (-1, -1, 1)]) def test_mul(self, a, b, c): result = self.calc.mul(a, b) assert c == result @pytest.mark.parametrize('a,b,c', [(0, 0, 0), (1, 1, 1), (-1, -1, 1)]) def test_div(self, a, b, c): result = self.calc.div(a, b) assert c == result
class TestCalc: def setup(self): self.calc=Calc() @pytest.mark.parametrize('a,b,c',yaml.safe_load(open("../datas/add.yml"))) def test_add(self, a, b, c): result = self.calc.add(a, b) assert c == result @pytest.mark.parametrize('a,b,c',[(0,0,0),(1,1,0),(-1,-1,0)]) def test_sub(self, a, b, c): result=self.calc.sub(a,b) assert c==result @pytest.mark.parametrize('a,b,c', [(0, 0, 0), (1, 1, 1), (-1, -1, 1)]) def test_mul(self, a, b, c): result = self.calc.mul(a, b) assert c == result @pytest.mark.parametrize('a,b,c', [(0, 0, 0), (1, 1, 1), (-1, -1, 1)]) def test_div(self, a, b, c): result = self.calc.div(a, b) assert c == result