def add(a,b): if isinstance(a,int) or isinstance(a,float): if isinstance(b,int) or isinstance(b,float): c = a+b return c else: print("请输入int 或float类型") return None else: print("请输入int 或float类型") return None if __name__ == '__main__': act1 = add(10,12) print(act1) assert act1 == 22 act2 = add('aaa',12) print(act2) assert act2 is None
from t7.test1 import add import unittest class TestAddFunction(unittest.TestCase): def test_add_01(self): act1 = add(10, 12) print(act1) self.assertEqual(act1,22) def test_add_02(self): act2 = add(10.22, 12) print(act2) self.assertTrue(act2 == 22) if __name__ == '__main__': unittest.main()
# coding:utf-8 import unittest class Test(unittest.TestCase): def setUp(self): print("打开浏览器") def tearDown(self): print("退出浏览器") def test_01(self): print("111") a = 2 b = 1 self.assertEqual(3, a+b) def test_02(self): print("22222222") a = 3 b = 4 self.assertEqual(1, b-a) if __name__ == "__main__": unittest.main()
# coding:utf-8 import unittest class Test(unittest.TestCase): @classmethod def setUpClass(cls): print("打开浏览器") @classmethod def tearDownClass(cls): print("退出浏览器") def test_01(self): print("测试用例1") a = 2 b = 1 self.assertEqual(3, a+b) def test_02(self): print("测试用例2") a = 3 b = 4 self.assertEqual(1, b-a) if __name__ == "__main__": unittest.main()
标签:__,框架,unittest,add,测试,print,self,def From: https://www.cnblogs.com/pingzi66-ww/p/17100271.html