[TOC] ## unittest模块 ``` import unittest def average(values): return sum(values) / len(values) #创建一个用于测试的类 class TestFunction(unittest.TestCase): def test_average(self): self.assertEqual(average([20, 30, 70]), 40.0) # 传入函数和结果 self.assertRaises(ZeroDivisionError, average, []) self.assertRaises(TypeError, average, 'as', 30, '70') unittest.main() ```