python3 unittest测试 ipython notebookDemo

mac2024-05-14  30

整理于2020年10月下旬,献给不甘平凡的你

更多企业级爬虫知识请查收于:https://blog.csdn.net/weixin_45316122/article/details/109843899

 

目录

一.实战Demo

二.unittest知识补充


一.实战Demo

2 import unittest class a(unittest.TestCase): def setup(self): print("启动了调定") def tarDown(self): print("Tearing down the test") def test_two(self): total = 2+2 self.assertEqual(4,total) if __name__ == '__main__': unittest.main(argv=[''],exit=False) . ---------------------------------------------------------------------- Ran 1 test in 0.001s OK 3 #数字 x = 2.3435 round(x,2) 3 2.34 7 <2>e<2> File "<ipython-input-7-b71bc519f518>", line 1 <2>e<2> ^ SyntaxError: invalid syntax 10 z = 2 +4j z.real # z.imag 输出是个实数 10 2.0 11 10//3 11 3 15 10%3 15 1 17 max(1,2,3,4,5,6) 17 6 19 int(10) 19 10 21 float(10 ) 21 10.0 22 len(10154) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-22-9bc3ca544176> in <module> ----> 1 len(10154) TypeError: object of type 'int' has no len() 26 #字符串 len('a b') 26 3 30 "ABc".lower() 30 'abc' 33 'B,C'.split(',') 33 ['B,C'] 36 "a ssa a".count("a") 36 3 38 "python".replace("n",".i") 38 'pytho.i' 41 "python".center(8,"=") 41 '=python=' 43 "python".strip("pn") 43 'ytho' 46 ",".join("12345") 46 '1,2,3,4,5' 52 "{1:=^20}".format("python","adad") #:引导 1,format的位数从0开始 =填充的东西 居中对齐,20输出长度 52 '========adad========' 55 "{:10}".format("bat") 55 'bat ' 57 "{0:,.2f}".format(123456.569) 57 '123,456.57' 71 a =1 a if a>0 else a<0 71 1 73 {1,2,3,4}|{2,3,4,5} 73 {1, 2, 3, 4, 5} 75 {1,2,3,4}-{2,3,4,5} 75 {1} 76 {1,2,3,4}|{2,3,4,5} 76 {1, 2, 3, 4, 5} 78 {1,2,3,4} & {2,3,4,5} 78 {2, 3, 4} 81 {1,2,3,4} ^ {2,3,4,5} 81 {1, 5} No output

二.unittest知识补充

python3+unittest参考

https://www.cnblogs.com/yizhipanghu/p/13516715.html

Python接口自动化测试之pytest与unittest区别

https://www.jianshu.com/p/db98f6f9b111

最新回复(0)