pytest框架基礎(一)

2022-07-11 12:21:12 字數 747 閱讀 1197

1.testcase測試用例

2.lib庫

3.報告

loghtml

4.data測試用例檔案--excel

5.config配置檔案

注意事項

.py測試檔案必須以test_開頭(或者以_test結尾)

測試類必須以test開頭,並且不能有init方法

測試方法必須以test_開頭

斷言必須使用assert

命令執行

在終端中切到相應目錄

test_login.py    .f   代表整個模組失敗

test_login.py    ..   成功是帶有兩個點的

test_login.py -s     執行命令加  -s  顯示所有列印資訊

assert斷言失敗下面語句就不會在執行

直接執行

if __name__ == "__main__":

pytest.main(['-s'])

也可以直接執行

pytest.main(['當前用例路徑','--html=測試報告/xx.html'])

安裝庫  pytest-html原生態的報告

test_login.py -s   --html=report.html

測試類一定要大寫test開頭命名

測試類中測試方法一定要test開頭

pytest會自動搜尋同級目錄中的conftest.py檔案

conftest主要做環境初始化和資料清除

測試框架 Pytest框架(一)

目錄 pytest的安裝與執行 安裝 執行執行方式及命令 ide中執行 命令列終端執行 生成報告 報告中的亂碼處理 檢查點 斷言 基於python語言的自動化常用的框架有三種,unittest pytest rf。前兩款更多的用於白盒單元測試,rf可以很好的做系統測試使用。安裝pytest pip ...

Pytest測試框架(一)

pip install u pytest 用下面的命令去檢查一下pytest是否成功安裝 pytest version this is pytest version 5.4.1 建立名為test 001.py的檔案,敲如下內容 def reverse string return string 1 d...

pytest框架介紹

一 pytest介紹 pytest是python的一種單元測試框架,與python自帶的unittest測試框架類似,但是比unittest框架使用起來更簡潔,效率更高。它具有如下特點 1.非常容易上手,入門簡單,文件豐富,文件中有很多例項可以參考 2.能夠支援簡單的單元測試和複雜的功能測試 3.支...