国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

pytest 框架自動化測試

這篇具有很好參考價值的文章主要介紹了pytest 框架自動化測試。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

隨筆記錄

目錄

1. 安裝?

2. 安裝pytest 相關(guān)插件

2.1 準(zhǔn)備階段

2.2 安裝?

2.3 驗證安裝成功?

3. pytest測試用例的運行方式

3.1 主函數(shù)模式

3.1.1 主函數(shù)執(zhí)行指定文件

?3.1.2?主函數(shù)執(zhí)行指定模塊

3.1.3 主函數(shù)執(zhí)行某個文件中的某個類、方法、函數(shù)

3.1.4?主函數(shù)執(zhí)行生成allure報告

3.2 命令行模式


1. 安裝?

1. install pycharm
2. install python 
3. config Envrionment variable

2. 安裝pytest 相關(guān)插件

2.1 準(zhǔn)備階段
# 將以下插件寫入 requirements.txt 中

pytest-rerunfailures         #用例失敗后重跑
pytest-xdist                 # 測試用例分布式執(zhí)行,多CPU 分發(fā)
pytest-ordering              # 控制用例執(zhí)行順序
pytest                       # pytest 框架
pytest-html                  # 生成html格式的自動化測試報告
allure-pytest                 # 用于生成美觀的測試報告

pytest 框架自動化測試,pytest

2.2 安裝?
terminal 執(zhí)行 以下命令,一次性安裝所有插件:
#  pip install -r .\requirements.txt  

pytest 框架自動化測試,pytest

2.3 驗證安裝成功?
執(zhí)行一下命令,驗證pytest 安裝成功

# pytest

PS D:\Backup\自動化腳本\Riskcop> pytest
================================================================================================================================================== test session starts =================================================================================================================================================== 
platform win32 -- Python 3.7.9, pytest-7.4.0, pluggy-1.0.0
rootdir: D:\Backup\自動化腳本\Riskcop
plugins: allure-pytest-2.13.2, anyio-3.6.1, Faker-18.10.1, assume-2.4.3, forked-1.4.0, html-3.1.1, metadata-2.0.1, ordering-0.6, rerunfailures-10.2, xdist-2.5.0
collected 0 items

================================================================================================================================================= no tests ran in 0.02s ================================================================================================================================================== 
PS D:\Backup\自動化腳本\Riskcop>

pytest 框架自動化測試,pytest文章來源地址http://www.zghlxwxcb.cn/news/detail-827357.html

3. pytest測試用例的運行方式

3.1 主函數(shù)模式
#主函數(shù)植式
1. 運行所有:pytest.main()

2. 指定模塊:
    # pytest main(['-vs','<文件名>'])
    # pytest.main(-vs','test login.py])

3. 指定目錄:
    # pytest main(['-vs','<模塊名>'])
    # pytest main(-vs','/interface_testcase])


4. 通過nodeid指定用例運行:nodeid由模塊名,分隔符(::),類名,方法名,函數(shù)名組成。

    4.1 運行指定函數(shù)
       # pytest main(['-vs','<模塊名>/<文件名>::<方法名>'])
       # pytest.main(['-vs','./interface_testcase/test_interface.py::test_04_func'])

    4.2 運行某個類中的某個方法
       # pytest main(['-vs','<模塊名>/<文件名>::<類名>::<方法名>'])
       # pytest main(['-       vs','./interface_testcase/test_interface.py::Testinterface::test_03_zhiliao'])


# 參數(shù)詳解:
-S:表示輸出調(diào)試信息,包括print打印的信息
-V:顯示更詳細(xì)的信息
-VS:這兩個參數(shù)一起用
分隔符- "::"
3.1.1 主函數(shù)執(zhí)行指定文件
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@文件    :main.py
@說明    :
@時間    :2024/01/22 17:07:32
@作者    :magx
@版本    :1.0
'''

import os
import time
import pytest

# 當(dāng)前路徑 (使用adbpath 方法 可通過dos 窗口執(zhí)行)
current_path = os.path.dirname(os.path.abspath(__file__))
print('current_path:',current_path)
# 上級目錄
father_path = os.path.abspath(os.path.join(current_path,".."))

# json 報告路徑
json_report_path = os.path.join(current_path, './Reports/json')
# html 報告路徑
html_report_path = os.path.join(current_path, './Reports/html')

def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.

if __name__ == '__main__':
    '''
    -v : 詳細(xì)信息 -  文件名:: 類名::方法名:
    -s : 表示輸出調(diào)試信息,包括print 打印的信息
    '''

    # 方式1:
    # 指定運行文件  "./TestCases/test_AccountLevel_2.py"
    # test_AccountLevel_2.py
    # test_MultiRule_12
    pytest.main(['-vs','./TestCases/test_AccountLevel_2.py'])   # test_AccountLevel_2.py

    
?3.1.2?主函數(shù)執(zhí)行指定模塊
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@文件    :main.py
@說明    :
@時間    :2024/01/22 17:07:32
@作者    :magx
@版本    :1.0
'''

import os
import time
import pytest

# 當(dāng)前路徑 (使用adbpath 方法 可通過dos 窗口執(zhí)行)
current_path = os.path.dirname(os.path.abspath(__file__))
print('current_path:',current_path)
# 上級目錄
father_path = os.path.abspath(os.path.join(current_path,".."))

# json 報告路徑
json_report_path = os.path.join(current_path, './Reports/json')
# html 報告路徑
html_report_path = os.path.join(current_path, './Reports/html')

def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.


if __name__ == '__main__':
    '''
    -v : 詳細(xì)信息 -  文件名:: 類名::方法名:
    -s : 表示輸出調(diào)試信息,包括print 打印的信息
    '''

    # 方式2: 運行指定模塊
    pytest.main(['-vs', './TestCases/'])

    
3.1.3 主函數(shù)執(zhí)行某個文件中的某個類、方法、函數(shù)
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@文件    :main.py
@說明    :
@時間    :2024/01/22 17:07:32
@作者    :magx
@版本    :1.0
'''

import os
import time
import pytest

# 當(dāng)前路徑 (使用adbpath 方法 可通過dos 窗口執(zhí)行)
current_path = os.path.dirname(os.path.abspath(__file__))
print('current_path:',current_path)
# 上級目錄
father_path = os.path.abspath(os.path.join(current_path,".."))

# json 報告路徑
json_report_path = os.path.join(current_path, './Reports/json')
# html 報告路徑
html_report_path = os.path.join(current_path, './Reports/html')

def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.

if __name__ == '__main__':

    '''
    -v : 詳細(xì)信息 -  文件名:: 類名::方法名:
    -s : 表示輸出調(diào)試信息,包括print 打印的信息
    '''


    # 方法3: 指定運行某個文件中的某個類、方法、函數(shù)
    # 模塊名/文件名::函數(shù)名
    # 文件名::類名::方法名
    pytest.main(['--vs','./TestCases/test_AccountLevel_2.py::cleanlog'])
3.1.4?主函數(shù)執(zhí)行生成allure報告
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@文件    :main.py
@說明    :
@時間    :2024/01/22 17:07:32
@作者    :magx
@版本    :1.0
'''

import os
import time
import pytest

# 當(dāng)前路徑 (使用adbpath 方法 可通過dos 窗口執(zhí)行)
current_path = os.path.dirname(os.path.abspath(__file__))
print('current_path:',current_path)
# 上級目錄
father_path = os.path.abspath(os.path.join(current_path,".."))

# json 報告路徑
json_report_path = os.path.join(current_path, './Reports/json')
# html 報告路徑
html_report_path = os.path.join(current_path, './Reports/html')

def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.

if __name__ == '__main__':

    '''
    -v : 詳細(xì)信息 -  文件名:: 類名::方法名:
    -s : 表示輸出調(diào)試信息,包括print 打印的信息
    '''

    # ===================================================================================
    # --alluredir生成json格式報告
    # allure generate 使用generate命令導(dǎo)出html報告,json_report_path json格式報告路徑, -o生成報告到文件夾, --clean清空原來的報告
    #執(zhí)行pytest下的用例并生成json文件

    pytest.main(['-vs', './TestCases','--alluredir=%s' %json_report_path, '--clean-alluredir'])#, '--clean-alluredir'
    # 把json文件轉(zhuǎn)成html報告
    os.system('allure generate %s -o %s --clean' %(json_report_path, html_report_path))
3.2 命令行模式
# 命令行模式
1. 運行所有:pytest
2. 指定模塊:
    #  pytest -vs <文件名>
    #  pytest -vs test_login.py
3. 指定目錄:
    #  pytest-vs  <模塊名>
    #  pytest-vs ./interface_testcase
4. 指定目錄:
   通過nodeid指定用例運行:nodeid由模塊名,分隔符(::),類名,方法名,函數(shù)名組成

    #  pytest-vs ./interface testcase/test interface.py:test 04_func

到了這里,關(guān)于pytest 框架自動化測試的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 自動化測試框架 —— pytest框架入門篇

    今天就給大家說一說pytest框架。 今天這篇文章呢,會從以下幾個方面來介紹: 1、首先介紹一下pytest框架 2、帶大家安裝Pytest框架 3、使用pytest框架時需要注意的點 4、pytest的運行方式 5、pytest框架中常用的插件 pytest 是 python 的第三方單元測試框架,比自帶 unittest 更簡潔和高效

    2024年02月03日
    瀏覽(97)
  • pytest接口測試自動化框架

    目錄 pytest簡介及安裝 pytest的使用規(guī)則 pytest運行方式 主函數(shù)方式 命令行方式 跳過、標(biāo)記及預(yù)期失敗特殊場景處理 pytest前后置、夾具 pytest高級用法fixture pytest接口斷言 pytest結(jié)合allure-pytest生成allure測試報告 ????????談起用例管理框架:python中的unittest、pytest;java中的test

    2024年02月06日
    瀏覽(100)
  • 【自動化測試教程】 —— pytest 框架詳解 ~

    【自動化測試教程】 —— pytest 框架詳解 ~

    特點: 容易上手, 入門簡單, 文檔豐富, 文檔中有很多參考案例 支持簡單的單元測試和復(fù)雜的功能測試 支持參數(shù)化 執(zhí)行測試用例過程中, 支持跳過操作 支持重復(fù)失敗的case 支持運行Nose, unittest編寫測試用例 pytest支持很多第三方插件 方便和持續(xù)集成工具集成 斷言方法: assert res

    2024年02月12日
    瀏覽(103)
  • Selenium+Pytest自動化測試框架

    Selenium+Pytest自動化測試框架

    selenium自動化+ pytest測試框架 本章你需要 一定的python基礎(chǔ)——至少明白類與對象,封裝繼承 一定的selenium基礎(chǔ)——本篇不講selenium,不會的可以自己去看selenium中文翻譯網(wǎng) 測試框架有什么優(yōu)點呢: 代碼復(fù)用率高,如果不使用框架的話,代碼會很冗余 可以組裝日志、報告、郵件

    2024年02月07日
    瀏覽(87)
  • Selenium+Pytest自動化測試框架詳解

    Selenium+Pytest自動化測試框架詳解

    selenium自動化+ pytest測試框架 本章你需要 一定的python基礎(chǔ)——至少明白類與對象,封裝繼承; 一定的selenium基礎(chǔ)——本篇不講selenium,不會的可以自己去看selenium中文翻譯網(wǎng) 測試框架有什么優(yōu)點 代碼復(fù)用率高,如果不使用框架的話,代碼會很冗余 可以組裝日志、報告、郵件等

    2024年02月08日
    瀏覽(25)
  • 引入成熟的Pytest自動化測試框架

    引入成熟的Pytest自動化測試框架

    雖然我們能使用腳本編寫自動化測試框架,但沒有必要重復(fù)找車輪子, 引入成熟的自動化測試框架 即可, Pytest是目前最成熟、功能最全面的Python測試框架之一 ,簡單靈活、易于上手,可完全兼容其他測試框架如unitest,支持參數(shù)化和測試編排功能,擴展性強。 1、安裝Pytes

    2024年02月20日
    瀏覽(16)
  • Pytest自動化測試框架之Allure報告

    Pytest自動化測試框架之Allure報告

    Allure?Framework是一種靈活的、輕量級、多語言測試報告工具。 不僅可以以簡潔的網(wǎng)絡(luò)報告形式非常簡潔地顯示已測試的內(nèi)容, 而且還允許參與開發(fā)過程的每個人從日常執(zhí)行中提取最大程度的有用信息和測試。 從開發(fā)/測試的角度來看: Allure報告可以快速查看到缺陷點,可以將

    2024年02月06日
    瀏覽(291)
  • Selenium + Pytest自動化測試框架實戰(zhàn)(上)

    Selenium + Pytest自動化測試框架實戰(zhàn)(上)

    今天呢筆者想和大家來聊聊selenium自動化+ pytest測試框架,在這篇文章里你需要知道一定的python基礎(chǔ)——至少明白類與對象,封裝繼承;一定的selenium基礎(chǔ)。這篇文章不會selenium,不會的可以自己去看selenium中文翻譯網(wǎng)喲。 測試框架有什么優(yōu)點呢 : 代碼復(fù)用率高,如果不使用框

    2024年04月27日
    瀏覽(26)
  • 【Pytest實戰(zhàn)】Pytest+Allure+Jenkins自動化測試框架搭建

    【Pytest實戰(zhàn)】Pytest+Allure+Jenkins自動化測試框架搭建

    ??作者簡介: 小曾同學(xué).com,一個致力于測試開發(fā)的博主??,主要職責(zé):測試開發(fā)、CI/CD 如果文章知識點有錯誤的地方,還請大家指正,讓我們一起學(xué)習(xí),一起進步。?? 座右銘:不想當(dāng)開發(fā)的測試,不是一個好測試??。 如果感覺博主的文章還不錯的話,還請點贊、收藏哦

    2024年02月15日
    瀏覽(96)
  • 從0到1精通自動化測試,pytest自動化測試框架,skip跳過用例(八)

    從0到1精通自動化測試,pytest自動化測試框架,skip跳過用例(八)

    pytest.mark.skip可以標(biāo)記無法在某些平臺上運行的測試功能,或者希望自己失敗的測試功能 skip意味著只有在滿足某些條件時才希望測試通過,否則pytest應(yīng)該跳過運行測試。 常見示例是在非Windows平臺上跳過僅限Windows的測試,或跳過測試依賴于當(dāng)前不可用的外部資源(例如數(shù)據(jù)庫

    2024年02月11日
    瀏覽(83)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包