pytest and unittestsum() function
would require checking the output of sum()
against a known output
Truesum()
to [2, 3, 4] we get a different resultAssertionError is thrown with the
message "Should be 15"test_sum.py and this will become a test
caseunittest module contains both a testing
framework and test runnerassert statement| Method | Equivalent | Reverse |
|---|---|---|
assertEquals(a, b) |
a == b | assertNotEqual(a, b) |
assertTrue(x) |
bool(x) is True | n/a |
assertFalse(x) |
bool(x) is False | n/a |
assertIs(a, b) |
a is b | assertIsNot() |
assertIsNone(x) |
x is None | assertIsNotNone() |
assertIn(a, b) |
a in b | assertNotIn() |
assertIsInstance(a, b) |
isInstance(a, b) | assertNotIsInstance() |
test_ followed by the name of the function you
are testingimport unittest
class TestCases(unittest.TestCase):
def test_sum(self):
self.assertEqual(sum([4, 5, 6]), 15, 'Should be 15')Single Responsibility Principle