Pytest 執行用例

2021-10-01 04:22:40 字數 780 閱讀 6492

pytest 不止可以執行自己的用例,也可以執行 unittest 寫的用例。

pytest 有很多執行時引數,用於指定執行的用例、執行結果展示、外掛程式引數等。

pytest 有兩種執行方式:

命令列通過 pytest 命令執行

pytest 引數 引數值 ...
**中使用pytest.main(['引數1=引數值1', '引數2=引數值2'])
你安裝 pytest 之後就能直接使用 pytest 命令。如果你不能使用,請檢查python安裝目錄/scripts有沒有 加入環境變數。

pytest.main() 函式接收的引數是乙個列表,而不是網上部分文章中寫的是乙個字串。

比如,幾個常用的引數,展示執行的寫法:

兩種寫法分別是:

pytest -s -q --capture=no -m smoke
或者

pytest.main(

['-s'

,'-q'

,'--capture=no'

,'-m smoke'

])

使用上一節寫的用例執行一下,是不是用命令行會漂亮些?因為命令列中可以顯示顏色效果。

執行後,我們可以看到有一些結果標記,如.f等,和 unittest 一樣,那分別代表什麼意思?

pytest文件2 用例執行

1.檔名以test py檔案和 test.py 2.以test 開頭的函式 3.以test 開頭的類 4.以test 開頭的方法 5.所有的包pakege必須要有 init py檔案 1.執行目錄下所有的用例 pytest 檔名 2.執行乙個py檔案下用例 pytest 指令碼名稱.py 3.x 遇...

pytest執行多個mark用例

import pytest pytest.mark.desktop professional pytest.mark.特性1 def test 1 print 執行了桌面專業版特性1用例 assert true pytest.mark.desktop professional pytest.mark...

pytest 執行用例生成報告

1.pytest html pytest vs reruns 1 html report.html self contained html pytest vs reruns 1 html testreport date 0,4 date 5,2 date 8,2 time 0,2 time 3,2 ...