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

從0到1精通自動(dòng)化測試,pytest自動(dòng)化測試框架,使用自定義標(biāo)記mark(十一)

這篇具有很好參考價(jià)值的文章主要介紹了從0到1精通自動(dòng)化測試,pytest自動(dòng)化測試框架,使用自定義標(biāo)記mark(十一)。希望對大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

一、前言

pytest可以支持自定義標(biāo)記,自定義標(biāo)記可以把一個(gè)web項(xiàng)目劃分多個(gè)模塊,然后指定模塊名稱執(zhí)行

app自動(dòng)化的時(shí)候,如果想android和ios公用一套代碼時(shí),也可以使用標(biāo)記功能,標(biāo)明哪些是ios用例,哪些是android的,運(yùn)行代碼時(shí)候指定mark名稱運(yùn)行就可以

二、mark標(biāo)記

1.以下用例,標(biāo)記test_send_http()為webtest

# content of test_server.py
'''程序員曦曦'''

import pytest

@pytest.mark.webtest
def test_send_http():
    pass # perform some webtest test for your app

def test_something_quick():
    pass

def test_another():
    pass

class TestClass:
    def test_method(self):
        pass

if __name__ == "__main__":
    pytest.main(["-s", "test_server.py", "-m=webtest"])

只運(yùn)行用webtest標(biāo)記的測試,cmd運(yùn)行的時(shí)候,加個(gè)-m 參數(shù),指定參數(shù)值webtest

$ pytest -v -m webtest
============================= test session starts =============================
platform win32 -- Python 3.6.0, pytest-3.6.3, py-1.5.4, pluggy-0.6.0
rootdir: E:\MOMO\se, inifile:
plugins: metadata-1.7.0, html-1.19.0
collected 4 items / 3 deselected

test_server.py .

=================== 1 passed, 3 deselected in 0.10 seconds ====================

如果不想執(zhí)行標(biāo)記webtest的用例,那就用 " not webtest "

$ pytest -v -m "not webtest"
import pytest

'''程序員曦曦'''

@pytest.mark.webtest
def test_send_http():
    pass # perform some webtest test for your app
def test_something_quick():
    pass
def test_another():
    pass
class TestClass:
    def test_method(self):
        pass

if __name__ == "__main__":
    pytest.main(["-s", "test_server.py", "-m='not webtest'"])

運(yùn)行結(jié)果

============================= test session starts =============================
platform win32 -- Python 3.6.0, pytest-3.6.3, py-1.5.4, pluggy-0.6.0
rootdir: E:\MOMO\se, inifile:
plugins: metadata-1.7.0, html-1.19.0
collected 4 items

test_server.py ....

========================== 4 passed in 0.06 seconds ===========================

三、-v 指定的函數(shù)節(jié)點(diǎn)id

如果想指定運(yùn)行某個(gè).py模塊下,類里面的一個(gè)用例,如:TestClass里面testmethod用例
每個(gè)test開頭(或_test結(jié)尾)的用例,函數(shù)(或方法)的名稱就是用例的節(jié)點(diǎn)id,指定節(jié)點(diǎn)id運(yùn)行用-v 參數(shù)

$ pytest -v test_server.py::TestClass::test_method

pycharm運(yùn)行代碼

if __name__ == "__main__":
    pytest.main(["-v", "test_server.py::TestClass::test_method"])

運(yùn)行結(jié)果

============================= test session starts =============================
platform win32 -- Python 3.6.0, pytest-3.6.3, py-1.5.4, pluggy-0.6.0 -- E:\python36\python.exe
cachedir: .pytest_cache
metadata: {'Python': '3.6.0', 'Platform': 'Windows-10-10.0.17134-SP0', 'Packages': {'pytest': '3.6.3', 'py': '1.5.4', 'pluggy': '0.6.0'}, 'Plugins': {'metadata': '1.7.0', 'html': '1.19.0'}, 'JAVA_HOME': 'D:\\java\\jdk17'}
rootdir: E:\MOMO\se, inifile:
plugins: metadata-1.7.0, html-1.19.0
collecting ... collected 1 item

test_server.py::TestClass::test_method PASSED                            [100%]

========================== 1 passed in 0.06 seconds ===========================

當(dāng)然也能選擇運(yùn)行整個(gè)class

$ pytest -v test_server.py::TestClass

也能選擇多個(gè)節(jié)點(diǎn)運(yùn)行,多個(gè)節(jié)點(diǎn)中間空格隔開

$ pytest -v test_server.py::TestClass test_server.py::test_send_http

pycharm運(yùn)行參考

if __name__ == "__main__":
    pytest.main(["-v", "test_server.py::TestClass", "test_server.py::test_send_http"])

四、-k 匹配用例名稱

可以使用-k命令行選項(xiàng)指定在匹配用例名稱的表達(dá)式

$ pytest -v -k http
$ pytest -v -k http # running with the above defined example module
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_
?→PREFIX/bin/python3.5
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items / 3 deselected
test_server.py::test_send_http PASSED [100%]
================== 1 passed, 3 deselected in 0.12 seconds ==================

你也可以運(yùn)行所有的測試,根據(jù)用例名稱排除掉某些用例:

$ pytest -k “not send_http” -v
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_
?→PREFIX/bin/python3.5
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items / 1 deselected
test_server.py::test_something_quick PASSED [ 33%]
test_server.py::test_another PASSED [ 66%]
test_server.py::TestClass::test_method PASSED [100%]
================== 3 passed, 1 deselected in 0.12 seconds ==================

也可以同時(shí)選擇匹配 “http” 和“quick”

$ pytest -k “http or quick” -v
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y -- $PYTHON_
?→PREFIX/bin/python3.5
cachedir: .pytest_cache
rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items / 2 deselected
test_server.py::test_send_http PASSED [ 50%]
test_server.py::test_something_quick PASSED [100%]
================== 2 passed, 2 deselected in 0.12 seconds ==================

最后感謝每一個(gè)認(rèn)真閱讀我文章的人,禮尚往來總是要有的,雖然不是什么很值錢的東西,如果你用得到的話可以直接拿走:

【軟件測試技術(shù)交流(資料分享)】:320231853(備注C)http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=rS49sB1dBN6wjk4SbxAjX80YS65Zy8TH&authKey=tlP2KE7Sut5Dq7EvwkG55B%2B0sWc5WpLYbuRGFftTLHed0FB22lskhUs4Dnw6hQRP&noverify=0&group_code=320231853

從0到1精通自動(dòng)化測試,pytest自動(dòng)化測試框架,使用自定義標(biāo)記mark(十一)

生命不息,奮斗不止。每一份努力都不會(huì)被辜負(fù),只要堅(jiān)持不懈,終究會(huì)有回報(bào)。珍惜時(shí)間,追求夢想。不忘初心,砥礪前行。你的未來,由你掌握!

生命短暫,時(shí)間寶貴,我們無法預(yù)知未來會(huì)發(fā)生什么,但我們可以掌握當(dāng)下。珍惜每一天,努力奮斗,讓自己變得更加強(qiáng)大和優(yōu)秀。堅(jiān)定信念,執(zhí)著追求,成功終將屬于你!

只有不斷地挑戰(zhàn)自己,才能不斷地超越自己。堅(jiān)持追求夢想,勇敢前行,你就會(huì)發(fā)現(xiàn)奮斗的過程是如此美好而值得。相信自己,你一定可以做到!文章來源地址http://www.zghlxwxcb.cn/news/detail-511420.html

到了這里,關(guān)于從0到1精通自動(dòng)化測試,pytest自動(dòng)化測試框架,使用自定義標(biāo)記mark(十一)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

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

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

相關(guān)文章

  • 從0到1精通自動(dòng)化測試,pytest自動(dòng)化測試框架,測試用例setup和teardown(三)

    從0到1精通自動(dòng)化測試,pytest自動(dòng)化測試框架,測試用例setup和teardown(三)

    目錄 一、前言 二、用例運(yùn)行級別 三、函數(shù)式 1、setup_function / teardown_function 2、setup_module / teardown_module 四、類和方法 五、函數(shù)和類混合 學(xué)過 unittest 的都知道里面用前置和后置 setup 和 teardown 非常好用,在每次用例開始前和結(jié)束后都去執(zhí)行一次 當(dāng)然還有更高級一點(diǎn)的 setupCla

    2024年02月09日
    瀏覽(89)
  • 從0到1精通自動(dòng)化測試,pytest自動(dòng)化測試框架,fixture之a(chǎn)utouse=True(十二)

    從0到1精通自動(dòng)化測試,pytest自動(dòng)化測試框架,fixture之a(chǎn)utouse=True(十二)

    平常寫自動(dòng)化用例會(huì)寫一些前置的fixture操作,用例需要用到就直接傳該函數(shù)的參數(shù)名稱就行了。當(dāng)用例很多的時(shí)候,每次都傳這個(gè)參數(shù),會(huì)比較麻煩 fixture里面有個(gè)參數(shù)autouse,默認(rèn)是Fasle沒開啟的,可以設(shè)置為True開啟自動(dòng)使用fixture功能,這樣用例就不用每次都去傳參了 調(diào)用

    2024年02月11日
    瀏覽(122)
  • 從0到1精通自動(dòng)化測試,pytest自動(dòng)化測試框架,allure2生成html報(bào)告(史上最詳細(xì))(九)

    從0到1精通自動(dòng)化測試,pytest自動(dòng)化測試框架,allure2生成html報(bào)告(史上最詳細(xì))(九)

    allure是一個(gè)report框架,支持java的Junit/testng等框架,當(dāng)然也可以支持python的pytest框架,也可以集成到Jenkins上展示高大上的報(bào)告界面。 環(huán)境準(zhǔn)備: python3.6 windows環(huán)境 pycharm pytest-allure-adaptor allure2.7.0 java1.8 pip安裝 pytest-allure-adaptor,github地址:https://github.com/allure-framework/allure-pytest 如

    2024年02月11日
    瀏覽(526)
  • 超詳細(xì)從入門到精通,pytest自動(dòng)化測試框架實(shí)戰(zhàn)-fixture多樣玩法(九)

    超詳細(xì)從入門到精通,pytest自動(dòng)化測試框架實(shí)戰(zhàn)-fixture多樣玩法(九)

    在編寫測試用例,都會(huì)涉及到用例執(zhí)行之前的環(huán)境準(zhǔn)備工作,和用例執(zhí)行之后的環(huán)境清理工作。 代碼版的測試用例也不例外。 pytest自動(dòng)化測試框架:https://www.bilibili.com/video/BV18K411m7FH/ 在自動(dòng)化測試框架當(dāng)中,我們也需要編寫: 用例執(zhí)行之前的環(huán)境準(zhǔn)備工作代碼(前置工作代碼

    2023年04月11日
    瀏覽(94)
  • Pytest+selenium+allure+Jenkins自動(dòng)化測試框架搭建及使用

    Pytest+selenium+allure+Jenkins自動(dòng)化測試框架搭建及使用

    一、 ? ?環(huán)境搭建 1. ? ?Python下載及安裝 Python可應(yīng)用于多平臺包括windows, Linux 和 Mac OS X, 本文主要介紹windows環(huán)境下。你可以通過終端窗口輸入 \\\"python\\\" 命令來查看本地是否已經(jīng)安裝Python以及Python的安裝版本。 ? ? 如未安裝python, 推薦下載python 3.8.3以上版本,本文主要介紹window

    2024年01月18日
    瀏覽(99)
  • 自動(dòng)化測試(三):接口自動(dòng)化pytest測試框架

    自動(dòng)化測試(三):接口自動(dòng)化pytest測試框架

    API:Application Programming Interface 接口自動(dòng)化按照自動(dòng)化的工具可分為 基于 接口測試工具 的接口自動(dòng)化 eg1:Postman+Newman+git/Svn+Jenkins(基于Javascript語言)接口自動(dòng)化 Postman :創(chuàng)建和發(fā)送 API 請求,并對響應(yīng)進(jìn)行斷言和驗(yàn)證。 Newman : Postman 的命令行工具,它允許測試人員在沒有界

    2024年02月10日
    瀏覽(94)
  • Pytest自動(dòng)化測試框架---(單元測試框架)

    Pytest自動(dòng)化測試框架---(單元測試框架)

    unittest是python自帶的單元測試框架,它封裝好了一些校驗(yàn)返回的結(jié)果方法和一些用例執(zhí)行前的初始化操作,使得單元測試易于開展,因?yàn)樗囊子眯?,很多同學(xué)也拿它來做功能測試和接口測試,只需簡單開發(fā)一些功能(報(bào)告,初始化webdriver,或者h(yuǎn)ttp請求方法)便可實(shí)現(xiàn)。 但自

    2024年02月14日
    瀏覽(120)
  • pytest 框架自動(dòng)化測試

    pytest 框架自動(dòng)化測試

    隨筆記錄 目錄 1. 安裝? 2. 安裝pytest 相關(guān)插件 2.1 準(zhǔn)備階段 2.2 安裝? 2.3 驗(yàn)證安裝成功? 3. pytest測試用例的運(yùn)行方式 3.1 主函數(shù)模式 3.1.1 主函數(shù)執(zhí)行指定文件 ?3.1.2?主函數(shù)執(zhí)行指定模塊 3.1.3 主函數(shù)執(zhí)行某個(gè)文件中的某個(gè)類、方法、函數(shù) 3.1.4?主函數(shù)執(zhí)行生成allure報(bào)告 3.2 命令

    2024年02月19日
    瀏覽(98)
  • 自動(dòng)化測試框架 —— pytest框架入門篇

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

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

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

    2024年02月06日
    瀏覽(100)

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

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

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包