class TestCal: def setup(self): self.cal = Calculator() @pytest.mark.run(order=1) @pytest.mark.dependency(name='add') @pytest.mark.parametrize('a,b,c', yaml.safe_load(open('./data.yml', 'r'))['add']) def test_add(self, a, b, c): print(f"测试 {a} + {b} = {c}") assert c == self.cal.add(a, b) @pytest.mark.run(order=2) @pytest.mark.dependency(depends=["add"]) @pytest.mark.parametrize('a,b,c', yaml.safe_load(open('./data.yml', 'r'))['sub']) def test_sub(self, a, b, c): print(f"测试 {a} - {b} = {c}") assert c == self.cal.sub(a, b) @pytest.mark.run(order=4) @pytest.mark.dependency(depends=["mul"]) @pytest.mark.parametrize('a,b,c', yaml.safe_load(open('./data.yml', 'r'))['div']) def test_div(self, a, b, c): print(f"测试 {a} / {b} = {c}") assert c == self.cal.div(a, b) @pytest.mark.run(order=3) @pytest.mark.dependency(name='mul') @pytest.mark.parametrize('a,b,c', yaml.safe_load(open('./data.yml', 'r'))['mul']) def test_mul(self, a, b, c): print(f"测试 {a} * {b} = {c}") assert c == self.cal.mul(a, b)
class ModuleTest(unittest.TestCase): def setUp(self): self.calc = Calculator(8, 4) def tearDown(self): pass def test_add(self): result = self.calc.add() self.assertEqual(result, 12) def test_sub(self): result = self.calc.sub() self.assertEqual(result, 4) def test_mul(self): result = self.calc.mul() self.assertEqual(result, 32) def test_div(self): result = self.calc.div() self.assertEqual(result, 2)
def test_sub(self, a, b, c): cal = Calculator() assert c == cal.sub(a, b)
def check_sub(a, b, c): cal = Calculator() assert c == cal.sub(a, b)
def test_sub(): c = Calculator() result = c.sub(3, 4) assert result == -1