Xiang Wang @ 2019-02-27 10:56:52
import unittest
class MyTest(unittest.TestCase):
def test_divide_zero(self):
with self.assertRaises(ZeroDivisionError):
1/0
pass
if __name__ == "__main__":
unittest.main()
- assets methods
- assertEqual, assertNotEqual,
- assertTrue, assertFalse,
- assertIs, assertIsNot,
- assertIsNone, assertIsNotNone,
- assertIn(a, b), assertNotIn
- assertIsInstance, assertNotIsInstance
- assertRaises
with self.assertRaises(SomeException): do_something() 如果do_something 不报这个 SomeException, 就失败