def one(request): """returns MyInt(1)""" yield MyInt(1) print("tear down code of one fixture")
def zero(request): """returns MyInt(0)""" def fin(): print("tear down code of zero fixture") request.addfinalizer(fin) return MyInt(0)
def __add__(self, other): return MyInt(self.v + other.v)
def __sub__(self, other): return MyInt(self.v - other.v)
def test_add(self): """Testing adding functionality""" a = MyInt(2) b = MyInt(3) self.assertEqual(a + b, MyInt(5))
def process(op, a, b): if op == '+': return a + b if op == '-': return a - b if op == '==': return a == b if op == '!=': return a != b if op == '>': return a > b if op == '<': return a < b if op == '>=': return a >= b if op == '<=': return a <= b #Note sequence in 1st arg of parametrize and test_eval args are not same #Note the generated ids @pytest.mark.parametrize("a, op, b, expected", [ ( MyInt(2), '+', MyInt(2), MyInt(4)), pytest.param(MyInt(2), '-', MyInt(2), MyInt(0), marks=pytest.mark.addl), ]) def test_eval(a, b, op, expected): assert process(op,a,b) == expected #generated through pytest_generate_tests def test_many(param1, op, param2, op2, result): assert process(op2, process(op,param1,param2),result) #Test command line class TestMyInt: def test_commandline(self,commandMyInt):
def test_great(self): """Testing great comparision functionality""" a = MyInt(2) b = MyInt(3) self.assertGreater(a, b)
def test_less(self): """Testing less comparision functionality""" a = MyInt(2) b = MyInt(3) self.assertLess(a, b)
def test_add(self): '''testing add functionality''' a = MyInt(1) b = MyInt(2) self.assertEqual(a + b , MyInt(3))
def test_less(self): '''testing less than functionality''' a = MyInt(1) b = MyInt(2) self.assertLess(a,b)
def test_add(self): """Testing add functionality""" a = MyInt(2) b = MyInt(3) c = a+b self.assertEqual(c, MyInt(5))