1、在控制台執行
打開cmd,進入項目目錄
-
指定執行某個模塊 pytest testcases\Logistics\Platform\CarSource\test_CarSourceList.py
-
指定執行某個目錄及其子目錄的所有測試文件 pytest testcases\Logistics\Platform\CarSource
-
指定執行某個模塊的某個類的某個測試用例 pytest testcases\Logistics\Platform\Home_page\test_navigation.py::TestNavigation::test_08_navigation
更多用法參考使用參數
2、通過pytest代碼執行
直接執行RunTestCase.py【自動查找當前目錄下,以test_開頭的文件或者以_test結尾的py文件】
法一:args = ['--reruns', '1', '--html=' + './Report/' + HTML_NAME]
pytest.main(args) 【 []內的多個參數通過‘逗號,’進行分割】
法二:args="pytest -m Navigation"
os.system(args)
-
指定執行某個目錄/某個模塊/某個類/某個用例,用::連接 args = ['--reruns', '1', '--html=' + './Report/' + HTML_NAME,'-v','testcases\Logistics\Platform\CarSource\\test_CarrierShop.py::TestCarrierShop::test_01_carrierShop']
-
指定執行多個目錄/多個模塊/多個類 args = ['--reruns', '1', '--html=./Report/Report.html','-v', 'testcases\Logistics\Platform\CarSource', 'testcases\Logistics\Platform\Login', r'testcases\Logistics\Platform\Home_page\test_navigation.py']
-
指定關鍵字匹配來運行測試用例名字子串 (-k ) args = ['--reruns', '1', '--html=' + './Report/' + HTML_NAME,'-k','01','testcases\Logistics\Platform\CarSource']
-
指定執行某個標簽 (一次只能指定一個標簽)args = ['--reruns', '1', '--html=' + './Report/' + HTML_NAME,'-m','CarrierShopTest']
-
執行返回失敗的用例 args =['--reruns', '1', '--html=./Report/Report.html', '-v','--lf']
3、常用參數說明 pytest
-v:說明:可以輸出用例更加詳細的執行信息,比如用例所在的文件及用例名稱等
-S:說明:輸入我們用例中的調式信息,比如print的打印信息等
-m :說明:執行特定的測試用例,”標記“
-k: 說明:執行用例包含“關鍵字”的用例 ,"關鍵字"
-q: 說明:簡化控制台的輸出
--lf:當一次用例執行完成后,如果其中存在失敗的測試用例,那么我們可以使用此命令重新運行失敗的測試用例
--ff:如果上次測試用例出現失敗的用例,當使用--ff后,失敗的測試用例會首先執行,剩余的用例也會再次執行一次