Beispiel #1
0
class TestCalc1():
    def setup(self):
        self.cal = Calculator()

    @pytest.mark.add
    @pytest.mark.parametrize(('a', 'b', 'result'),
                             yaml.safe_load(open(r'../datas/calc.yml'))['add'])
    def test_add(self, a, b, result, open1):
        print(f"计算数据:  a={a}, b={b}, result={result}")
        assert self.cal.add(a, b) == result

    @pytest.mark.div
    @pytest.mark.parametrize(('a', 'b', 'result'),
                             yaml.safe_load(open(r'../datas/calc.yml'))['div'])
    def test_div(self, a, b, result, open1):
        print(f"计算数据:  a={a}, b={b}, result={result}")
        assert self.cal.div(a, b) == result

    @pytest.mark.mul
    @pytest.mark.parametrize(('a', 'b', 'result'),
                             yaml.safe_load(open(r'../datas/calc.yml'))['mul'])
    def test_mul(self, a, b, result, open1):
        print(f"计算数据:  a={a}, b={b}, result={result}")
        assert self.cal.mul(a, b) == result

    @pytest.mark.sub
    @pytest.mark.parametrize(('a', 'b', 'result'),
                             yaml.safe_load(open(r'../datas/calc.yml'))['sub'])
    def test_sub(self, a, b, result, open1):
        print(f"计算数据: a={a}, b={b}, result={result}")
        assert self.cal.sub(a, b) == result
Beispiel #2
0
class TestCalc:
    def setup_class(self):
        self.cal = Calculator()

    @pytest.mark.parametrize(
        ['a', 'b', 'result'],
        yaml.safe_load(open("./data.yaml"))['add'],
        ids=['int', 'big num', 'xiaoshu', 'fushu', 'xiaoshu1'])
    def test_add(self, a, b, result):
        assert Decimal(result) == self.cal.add(a, b)

    @pytest.mark.parametrize(['a', 'b', 'result'],
                             yaml.safe_load(open('./data.yaml'))['sub'],
                             ids=['int', 'big num', 'xiaoshu', 'fushu'])
    def test_sub(self, a, b, result):
        assert Decimal(result) == self.cal.sub(a, b)

    @pytest.mark.parametrize(['a', 'b', 'result'],
                             yaml.safe_load(open('./data.yaml'))['mul'],
                             ids=['int', 'big num', 'xiaoshu', 'fushu'])
    def test_mul(self, a, b, result):
        assert Decimal(result) == self.cal.mul(a, b)

    @pytest.mark.parametrize(['a', 'b', 'result'],
                             yaml.safe_load(open('./data.yaml'))['div'],
                             ids=['int', 'big num', 'xiaoshu', 'fushu'])
    def test_div(self, a, b, result):
        assert Decimal(result) == self.cal.div(a, b)
class CheckCalc():
    def setup(self):
        self.cal = Calculator()

    # 加法
    @pytest.mark.first
    @pytest.mark.dependency()
    @pytest.mark.parametrize("a,b,result", adddatas, ids=addids)
    def check_add(self, a, b, result):
        print(f"\n计算数据:a={a},b={b},result={result}")
        assert self.cal.add(a, b) == result

    #除法
    @pytest.mark.last
    @pytest.mark.dependency(depends=["test_mul"])
    @pytest.mark.parametrize("a,b,result", divdatas, ids=divids)
    def check_div(self, a, b, result):
        print(f"\n计算数据:a={a},b={b},result={result}")
        assert self.cal.div(a, b) == result

    # 减法
    @pytest.mark.second
    @pytest.mark.dependency(depends=["test_add"])
    @pytest.mark.parametrize("a,b,result", subdatas, ids=subids)
    def check_sub(self, a, b, result):
        print(f"\n计算数据:a={a},b={b},result={result}")
        assert self.cal.sub(a, b) == result

    #乘法
    @pytest.mark.third
    @pytest.mark.dependency()
    @pytest.mark.parametrize("a,b,result", muldatas, ids=mulids)
    def check_mul(self, a, b, result):
        print(f"\n计算数据:a={a},b={b},result={result}")
        assert self.cal.mul(a, b) == result
Beispiel #4
0
 def test_sub(self,a,b,c):
     """
     减法测试用例
     :param a:
     :param b:
     :param c:
     :return:
     """
     cal = Calculator()
     print(f'\na,b,c的值:{a} - {b} = {c}')
     assert cal.sub(a,b) == c
class TestCalc:

    def setup_class(self):
        self.cal = Calculator()

    @pytest.mark.run(order=2)
    @pytest.mark.dependency(name="add")
    # @pytest.mark.xfail(reason="deliberate fail")
    @pytest.mark.parametrize('read', c, ids=ids_add, indirect=True)
    def check_add(self, read):
        print(f"计算:{read[0]} + {read[1]},预期结果为:{read[2]}")
        try:
            temp_result = self.cal.add(read[0], read[1])
            assert temp_result == read[2]
        except Exception as e:
            print(e)
            assert False

    @pytest.mark.run(order=3)
    @pytest.mark.dependency(depends=["add"])
    @pytest.mark.parametrize('read', c, ids=ids_sub, indirect=True)
    def check_sub(self, read):
        print(f"计算:{read[0]} - {read[1]},预期结果为:{read[3]}")
        try:
            temp_result = self.cal.sub(read[0], read[1])
            assert temp_result == read[3]
        except Exception as e:
            print(e)
            assert False

    @pytest.mark.run(order=4)
    @pytest.mark.dependency(name="mul")
    @pytest.mark.parametrize('read', c, ids=ids_mul, indirect=True)
    def check_mul(self, read):
        print(f"计算:{read[0]} * {read[1]},预期结果为:{read[4]}")
        try:
            temp_result = self.cal.mul(read[0], read[1])
            assert temp_result == read[4]
        except Exception as e:
            print(e)
            assert False

    @pytest.mark.run(order=5)
    @pytest.mark.dependency(depends=["mul"])
    @pytest.mark.parametrize('read', c, ids=ids_div, indirect=True)
    def check_div(self, read):
        print(f"计算:{read[0]} ÷ {read[1]},预期结果为:{read[5]}")
        try:
            temp_result = self.cal.div(read[0], read[1])
            assert temp_result == read[5]
        except Exception as e:
            print(e)
            assert False
class CheckCalc():

    def setup(self):
        self.cal = Calculator()

    @pytest.mark.parametrize("a,b,result", adddatas, ids=addids)
    def check_add(self, a, b, result):
        print(f"\n计算数据:a={a},b={b},result={result}")
        assert self.cal.add(a, b) == result

    @pytest.mark.parametrize("a,b,result", divdatas, ids=divids)
    def check_div(self, a, b, result):
        print(f"\n计算数据:a={a},b={b},result={result}")
        assert self.cal.div(a, b) == result

    @pytest.mark.parametrize("a,b,result", subdatas, ids=subids)
    def check_sub(self, a, b, result):
        print(f"\n计算数据:a={a},b={b},result={result}")
        assert self.cal.sub(a, b) == result

    @pytest.mark.parametrize("a,b,result", muldatas, ids=mulids)
    def check_mul(self, a, b, result):
        print(f"\n计算数据:a={a},b={b},result={result}")
        assert self.cal.mul(a, b) == result
 def test_sub(self, a, b, forward):
     cal = Calculator()
     assert a - b == cal.sub(a, b)