pytest之指定測試範圍

2021-10-04 12:48:03 字數 661 閱讀 7370

本文總結如何指定pytest當次執行的覆蓋範圍。總體來說,可以指定執行單個測試目錄,單個檔案,單個測試類,單個測試類中的方法,單個函式。而這些指定僅和乙個引數有關。

首先看示例程式的目錄結構:

以示例說明:

# 指定執行單個測試目錄

pytest.main(

['./test_case'])

# 指定執行單個測試檔案

pytest.main(

['./test_case/test_func.py'])

# 指定執行測試類

pytest.main(

['./test_case/test_func.py::testfunc'])

# 指定執行測試類中的某個方法

pytest.main(

['./test_case/test_func.py::testfunc::test_add_by_class'])

# 指定執行單個測試函式

pytest.main(

['./test_case/test_func.py::test_add_by_func_aaa'

])

單元測試之pytest

前提 需要安裝pytest和pytest html 生成html測試報告 pip install pytest 和 pip install pytest htmlpytest單元測試中的類名和方法名必須是以test開頭,執行中只能找到test開頭的類和方法,比unittest更加嚴謹unittest...

python測試模組pytest之坑

pytest是pyhon測試 模組,只要你安裝了pytest就可以生成txt,xml,html等測試結果集,注意 生成html需要安裝pytest html模組。pytest會尋找test或者test 開頭的函式,test開頭的類去測試。我在使用pytest的時候就遇到了大坑,總結一下 很多教程都是...

Python測試框架之pytest簡單應用

pytest框架簡介 1 python的第三方單元測試框架,比自帶unittest更簡單和高效,支援315種以上的外掛程式,同時相容unittest框架。2 unittest框架遷移到pytest框架的時候不需要重寫 3 純python 的自動化測試框架。4 可以很好的與jenkins整合。5 al...