pycharm運行三種方式
1.以xx.py腳本方式直接執行,當寫的代碼里面沒用到unittest和pytest框架時,並且腳本名稱不是以test_開頭命名的,此時pycharm會以xx.py腳本方式運行
2.當腳本命名為test_xx.py時,用到unittest框架,此時運行代碼,pycharm會自動識別到以unittest方式運行
eg: test.hello.py
import unittest class Test1(unittest.TestCase): def test_hello(self): print("hello world!") if __name__=="__main__": unittest.main()
3.以pytest方式運行,需要改該工程設置默認的運行器:file->Setting->Tools->Python Integrated Tools->項目名稱->Default test runner->選擇py.test
備注:pytest是可以兼容unittest框架代碼的