亚欧色一区w666天堂,色情一区二区三区免费看,少妇特黄A片一区二区三区,亚洲人成网站999久久久综合,国产av熟女一区二区三区

  • 發布文章
  • 消息中心
點贊
收藏
評論
分享
原創

pytest --python單元測試插件使用方法

2024-11-14 09:41:51
5
0

### 插件安裝:
pip install pytest-testreport

注意點:如果安裝了pytest-html這個插件請先卸載,不然有可能會有沖突

### 命令行運行:
生成測試報告, 運行測試時加上參數--report指定報告文件名,即可實現。其他參數如下:
--title :指定報告標題
--tester :指定報告中的測試者
--desc :指定報告中的項目描述
--template :指定報告模板樣式(1 or 2)
python3 test_tools.py --report=report.html --title=單元測試報告 --tester=開發 --desc=iptv主備中心單元測試報告 --template=2

備注:
1.上述命令自動生成本目錄下所有測試用例的測試報告。
2.python3 xxx.py 執行目錄下所有測試用例。
3.pytest xxx.py 執行單個文件內的測試用例。


### unittest mock 斷言示例

- assert_not_called: 模擬從未被調用過
- assert_called_once: 模擬只被調用過一次
- assert_called_with: 模擬被調用過,并檢查參數
- assert_called_once_with: 模擬只被調用過一次,并檢查參數
- assert_any_call: 模擬至少調用過一次,并檢查參數
- assert_has_calls: 模擬至少調用過一次,并檢查參數
- assert_called: 模擬至少調用過一次

### pytest執行unittest測試用例,建議使用指定python版本情況(特別是在虛擬環境下)

>進行test目錄下執行: python3 -m pytest -v xxx_test.py


### 代碼覆蓋率統計
1.安裝:pip install pytest-cov
2.執行:pytest --cov=./ --cov-report=html
3.查看:打開html文件,查看代碼覆蓋率情況

- 查看單個文件的覆蓋率:pytest test_xxx.py --cov
0條評論
0 / 1000
****偉
4文章數
0粉絲數
****偉
4 文章 | 0 粉絲
原創

pytest --python單元測試插件使用方法

2024-11-14 09:41:51
5
0

### 插件安裝:
pip install pytest-testreport

注意點:如果安裝了pytest-html這個插件請先卸載,不然有可能會有沖突

### 命令行運行:
生成測試報告, 運行測試時加上參數--report指定報告文件名,即可實現。其他參數如下:
--title :指定報告標題
--tester :指定報告中的測試者
--desc :指定報告中的項目描述
--template :指定報告模板樣式(1 or 2)
python3 test_tools.py --report=report.html --title=單元測試報告 --tester=開發 --desc=iptv主備中心單元測試報告 --template=2

備注:
1.上述命令自動生成本目錄下所有測試用例的測試報告。
2.python3 xxx.py 執行目錄下所有測試用例。
3.pytest xxx.py 執行單個文件內的測試用例。


### unittest mock 斷言示例

- assert_not_called: 模擬從未被調用過
- assert_called_once: 模擬只被調用過一次
- assert_called_with: 模擬被調用過,并檢查參數
- assert_called_once_with: 模擬只被調用過一次,并檢查參數
- assert_any_call: 模擬至少調用過一次,并檢查參數
- assert_has_calls: 模擬至少調用過一次,并檢查參數
- assert_called: 模擬至少調用過一次

### pytest執行unittest測試用例,建議使用指定python版本情況(特別是在虛擬環境下)

>進行test目錄下執行: python3 -m pytest -v xxx_test.py


### 代碼覆蓋率統計
1.安裝:pip install pytest-cov
2.執行:pytest --cov=./ --cov-report=html
3.查看:打開html文件,查看代碼覆蓋率情況

- 查看單個文件的覆蓋率:pytest test_xxx.py --cov
文章來自個人專欄
文章 | 訂閱
0條評論
0 / 1000
請輸入你的評論
0
0