中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

軟件開發(fā)步驟及周期長沙優(yōu)化網(wǎng)站廠家

軟件開發(fā)步驟及周期,長沙優(yōu)化網(wǎng)站廠家,可以做設(shè)計(jì)兼職的網(wǎng)站有哪些工作室,微信開發(fā)者工具代碼怎么寫Pytest擁有豐富的插件架構(gòu),超過800個(gè)以上的外部插件和活躍的社區(qū),在PyPI項(xiàng)目中以“ pytest- *”為標(biāo)識(shí)。 本篇將列舉github標(biāo)星超過兩百的一些插件進(jìn)行實(shí)戰(zhàn)演示。 插件庫地址:http://plugincompat.herokuapp.com/ 1、pytest-html&#xff1…

Pytest擁有豐富的插件架構(gòu),超過800個(gè)以上的外部插件和活躍的社區(qū),在PyPI項(xiàng)目中以“ pytest- *”為標(biāo)識(shí)。

本篇將列舉github標(biāo)星超過兩百的一些插件進(jìn)行實(shí)戰(zhàn)演示。

插件庫地址:http://plugincompat.herokuapp.com/


1、pytest-html:用于生成HTML報(bào)告

一次完整的測(cè)試,測(cè)試報(bào)告是必不可少的,但是pytest自身的測(cè)試結(jié)果過于簡單,而pytest-html正好可以給你提供一份清晰報(bào)告。

安裝:
pip install -U pytest-html
用例:

# test_sample.py
import pytest
# import time# 被測(cè)功能
def add(x, y):# time.sleep(1)return x + y# 測(cè)試類
class TestLearning:data = [[3, 4, 7],[-3, 4, 1],[3, -4, -1],[-3, -4, 7],]@pytest.mark.parametrize("data", data)def test_add(self, data):assert add(data[0], data[1]) == data[2]

運(yùn)行:

E:\workspace-py\Pytest>pytest test_sample.py --html=report/index.html
========================================================================== test session starts ==========================================================================
platform win32 -- Python 3.7.3, pytest-6.0.2, py-1.9.0, pluggy-0.13.0
rootdir: E:\workspace-py\Pytest
plugins: allure-pytest-2.8.18, cov-2.10.1, html-3.0.0, rerunfailures-9.1.1, xdist-2.1.0
collected 4 items                                                                                                                                                        test_sample.py ...F                                                                                                                                                [100%]=============================================================================== FAILURES ================================================================================
_____________________________________________________________________ TestLearning.test_add[data3] ______________________________________________________________________self = <test_sample.TestLearning object at 0x00000000036B6AC8>, data = [-3, -4, 7]@pytest.mark.parametrize("data", data)def test_add(self, data):
>       assert add(data[0], data[1]) == data[2]
E       assert -7 == 7
E        +  where -7 = add(-3, -4)test_sample.py:20: AssertionError
------------------------------------------------- generated html file: file://E:\workspace-py\Pytest\report\index.html --------------------------------------------------
======================================================================== short test summary info ========================================================================
FAILED test_sample.py::TestLearning::test_add[data3] - assert -7 == 7
====================================================================== 1 failed, 3 passed in 0.14s ======================================================================

運(yùn)行完,會(huì)生產(chǎn)一個(gè)html文件 和 css樣式文件夾assets,用瀏覽器打開html即可查看清晰的測(cè)試結(jié)果。

?

后面我將會(huì)更新更加清晰美觀的測(cè)試報(bào)告插件:?allure-python


2、pytest-cov:用于生成覆蓋率報(bào)告

在做單元測(cè)試時(shí),代碼覆蓋率常常被拿來作為衡量測(cè)試好壞的指標(biāo),甚至,用代碼覆蓋率來考核測(cè)試任務(wù)完成情況。

安裝:
pip install -U pytest-cov
?運(yùn)行:

E:\workspace-py\Pytest>pytest --cov=.
========================================================================== test session starts ==========================================================================
platform win32 -- Python 3.7.3, pytest-6.0.2, py-1.9.0, pluggy-0.13.0
rootdir: E:\workspace-py\Pytest
plugins: allure-pytest-2.8.18, cov-2.10.1, html-3.0.0, rerunfailures-9.1.1, xdist-2.1.0
collected 4 items                                                                                                                                                        test_sample.py ....                                                                                                                                                [100%]----------- coverage: platform win32, python 3.7.3-final-0 -----------
Name             Stmts   Miss  Cover
------------------------------------
conftest.py          5      3    40%
test_sample.py       7      0   100%
------------------------------------
TOTAL               12      3    75%=========================================================================== 4 passed in 0.06s ===========================================================================


3、pytest-xdist:實(shí)現(xiàn)多線程、多平臺(tái)執(zhí)行

通過將測(cè)試發(fā)送到多個(gè)CPU來加速運(yùn)行,可以使用-n NUMCPUS指定具體CPU數(shù)量,或者使用-n auto自動(dòng)識(shí)別CPU數(shù)量并全部使用。

安裝:
pip install -U pytest-xdist
用例:

# test_sample.py
import pytest
import time# 被測(cè)功能
def add(x, y):time.sleep(3)return x + y# 測(cè)試類
class TestAdd:def test_first(self):assert add(3, 4) == 7def test_second(self):assert add(-3, 4) == 1def test_three(self):assert add(3, -4) == -1def test_four(self):assert add(-3, -4) == 7

?運(yùn)行:

E:\workspace-py\Pytest>pytest test_sample.py
========================================================================== test session starts ==========================================================================
platform win32 -- Python 3.7.3, pytest-6.0.2, py-1.9.0, pluggy-0.13.0
rootdir: E:\workspace-py\Pytest
plugins: allure-pytest-2.8.18, cov-2.10.1, html-3.0.0, rerunfailures-9.1.1, xdist-2.1.0
collected 4 items                                                                                                                                                        test_sample.py ....                                                                                                                                                [100%]========================================================================== 4 passed in 12.05s ===========================================================================E:\workspace-py\Pytest>pytest test_sample.py -n auto
========================================================================== test session starts ==========================================================================
platform win32 -- Python 3.7.3, pytest-6.0.2, py-1.9.0, pluggy-0.13.0
rootdir: E:\workspace-py\Pytest
plugins: allure-pytest-2.8.18, assume-2.3.3, cov-2.10.1, forked-1.3.0, html-3.0.0, rerunfailures-9.1.1, xdist-2.1.0
gw0 [4] / gw1 [4] / gw2 [4] / gw3 [4]
....                                                                                                                                                               [100%]
=========================================================================== 4 passed in 5.35s ===========================================================================E:\workspace-py\Pytest>pytest test_sample.py -n 2
========================================================================== test session starts ==========================================================================
platform win32 -- Python 3.7.3, pytest-6.0.2, py-1.9.0, pluggy-0.13.0
rootdir: E:\workspace-py\Pytest
plugins: allure-pytest-2.8.18, assume-2.3.3, cov-2.10.1, forked-1.3.0, html-3.0.0, rerunfailures-9.1.1, xdist-2.1.0
gw0 [4] / gw1 [4]
....                                                                                                                                                               [100%]
=========================================================================== 4 passed in 7.65s ===========================================================================

上述分別進(jìn)行了未開多并發(fā)、開啟4個(gè)cpu、開啟2個(gè)cpu,從運(yùn)行耗時(shí)結(jié)果來看,很明顯多并發(fā)可以大大縮減你的測(cè)試用例運(yùn)行耗時(shí)。


4、pytest-rerunfailures:實(shí)現(xiàn)重新運(yùn)行失敗用例

?我們?cè)跍y(cè)試時(shí)可能會(huì)出現(xiàn)一些間接性故障,比如接口測(cè)試遇到網(wǎng)絡(luò)波動(dòng),web測(cè)試遇到個(gè)別插件刷新不及時(shí)等,這時(shí)重新運(yùn)行則可以幫忙我們消除這些故障。

?安裝:
pip install -U pytest-rerunfailures
運(yùn)行:

E:\workspace-py\Pytest>pytest test_sample.py --reruns 3
========================================================================== test session starts ==========================================================================
platform win32 -- Python 3.7.3, pytest-6.0.2, py-1.9.0, pluggy-0.13.0
rootdir: E:\workspace-py\Pytest
plugins: allure-pytest-2.8.18, cov-2.10.1, html-3.0.0, rerunfailures-9.1.1, xdist-2.1.0
collected 4 items                                                                                                                                                        test_sample.py ...R                                                                                                                                                [100%]R[100%]R [100%]F [100%]=============================================================================== FAILURES ================================================================================
___________________________________________________________________________ TestAdd.test_four ___________________________________________________________________________self = <test_sample.TestAdd object at 0x00000000045FBF98>def test_four(self):
>       assert add(-3, -4) == 7
E       assert -7 == 7
E        +  where -7 = add(-3, -4)test_sample.py:22: AssertionError
======================================================================== short test summary info ========================================================================
FAILED test_sample.py::TestAdd::test_four - assert -7 == 7
================================================================= 1 failed, 3 passed, 3 rerun in 0.20s ==================================================================

如果你想設(shè)定重試間隔,可以使用?--rerun-delay?參數(shù)指定延遲時(shí)長(單位秒);?

如果你想重新運(yùn)行指定錯(cuò)誤,可以使用?--only-rerun?參數(shù)指定正則表達(dá)式匹配,并且可以使用多次來匹配多個(gè)。

pytest --reruns 5 --reruns-delay 1 --only-rerun AssertionError --only-rerun ValueError

如果你只想標(biāo)記單個(gè)測(cè)試失敗時(shí)自動(dòng)重新運(yùn)行,可以添加?pytest.mark.flaky()?并指定重試次數(shù)以及延遲間隔。

@pytest.mark.flaky(reruns=5, reruns_delay=2)
def test_example():import randomassert random.choice([True, False])


5、pytest-randomly:實(shí)現(xiàn)隨機(jī)排序測(cè)試

測(cè)試中的隨機(jī)性非常越大越容易發(fā)現(xiàn)測(cè)試本身中隱藏的缺陷,并為你的系統(tǒng)提供更多的覆蓋范圍。

安裝:
pip install -U pytest-randomly
運(yùn)行:

E:\workspace-py\Pytest>pytest test_sample.py
========================================================================== test session starts ==========================================================================
platform win32 -- Python 3.7.3, pytest-6.0.2, py-1.9.0, pluggy-0.13.0
Using --randomly-seed=3687888105
rootdir: E:\workspace-py\Pytest
plugins: allure-pytest-2.8.18, cov-2.10.1, html-3.0.0, randomly-3.5.0, rerunfailures-9.1.1, xdist-2.1.0
collected 4 items                                                                                                                                                        test_sample.py F...                                                                                                                                                [100%]=============================================================================== FAILURES ================================================================================
___________________________________________________________________________ TestAdd.test_four ___________________________________________________________________________self = <test_sample.TestAdd object at 0x000000000567AD68>def test_four(self):
>       assert add(-3, -4) == 7
E       assert -7 == 7
E        +  where -7 = add(-3, -4)test_sample.py:22: AssertionError
======================================================================== short test summary info ========================================================================
FAILED test_sample.py::TestAdd::test_four - assert -7 == 7
====================================================================== 1 failed, 3 passed in 0.13s ======================================================================E:\workspace-py\Pytest>pytest test_sample.py
========================================================================== test session starts ==========================================================================
platform win32 -- Python 3.7.3, pytest-6.0.2, py-1.9.0, pluggy-0.13.0
Using --randomly-seed=3064422675
rootdir: E:\workspace-py\Pytest
plugins: allure-pytest-2.8.18, assume-2.3.3, cov-2.10.1, forked-1.3.0, html-3.0.0, randomly-3.5.0, rerunfailures-9.1.1, xdist-2.1.0
collected 4 items                                                                                                                                                        test_sample.py ...F                                                                                                                                                [100%]=============================================================================== FAILURES ================================================================================
___________________________________________________________________________ TestAdd.test_four ___________________________________________________________________________self = <test_sample.TestAdd object at 0x00000000145EA940>def test_four(self):
>       assert add(-3, -4) == 7
E       assert -7 == 7
E        +  where -7 = add(-3, -4)test_sample.py:22: AssertionError
======================================================================== short test summary info ========================================================================
FAILED test_sample.py::TestAdd::test_four - assert -7 == 7
====================================================================== 1 failed, 3 passed in 0.12s ======================================================================

這功能默認(rèn)情況下處于啟用狀態(tài),但可以通過標(biāo)志禁用(假如你并不需要這個(gè)模塊,建議就不要安裝)。

pytest -p no:randomly

如果你想指定隨機(jī)順序,可以通過?--randomly-send?參數(shù)來指定,也可以使用?last?值來指定沿用上次的運(yùn)行順序。

pytest --randomly-seed=4321
pytest --randomly-seed=last

6、其他活躍的插件

還有一些其他功能性比較活躍的、一些專門為個(gè)別框架所定制的、以及為了兼容其他測(cè)試框架,這里暫不做演示,我就簡單的做個(gè)列舉:

pytest-django:用于測(cè)試Django應(yīng)用程序(Python Web框架)。

pytest-flask:用于測(cè)試Flask應(yīng)用程序(Python Web框架)。

pytest-splinter:兼容Splinter Web自動(dòng)化測(cè)試工具。

pytest-selenium:兼容Selenium Web自動(dòng)化測(cè)試工具。

pytest-testinfra:測(cè)試由Salt,Ansible,Puppet,?Chef等管理工具配置的服務(wù)器的實(shí)際狀態(tài)。

pytest-mock:提供一個(gè)mock固件,創(chuàng)建虛擬的對(duì)象來實(shí)現(xiàn)測(cè)試中個(gè)別依賴點(diǎn)。

pytest-factoryboy:結(jié)合factoryboy工具用于生成各式各樣的數(shù)據(jù)。

pytest-qt:提供為PyQt5和PySide2應(yīng)用程序編寫測(cè)試。

pytest-asyncio:用于使用pytest測(cè)試異步代碼。

pytest-bdd:實(shí)現(xiàn)了Gherkin語言的子集,以實(shí)現(xiàn)自動(dòng)化項(xiàng)目需求測(cè)試并促進(jìn)行為驅(qū)動(dòng)的開發(fā)。

pytest-watch:為pytest提供一套快捷CLI工具。

pytest-testmon:可以自動(dòng)選擇并重新執(zhí)行僅受最近更改影響的測(cè)試。

pytest-assume:用于每個(gè)測(cè)試允許多次失敗。

pytest-ordering:用于測(cè)試用例的排序功能。

pytest-sugar:可立即顯示失敗和錯(cuò)誤并顯示進(jìn)度條。

pytest-dev/pytest-repeat:可以重復(fù)(可指定次數(shù))執(zhí)行單個(gè)或多個(gè)測(cè)試。

http://www.risenshineclean.com/news/50510.html

相關(guān)文章:

  • 韓國購物網(wǎng)站廣告素材
  • 宿州商務(wù)網(wǎng)站建設(shè)網(wǎng)站關(guān)鍵詞優(yōu)化有用嗎
  • java畢業(yè)設(shè)計(jì)網(wǎng)站建設(shè)培訓(xùn)網(wǎng)址大全
  • 公司建站比較好的金華網(wǎng)站建設(shè)
  • 專門做車評(píng)的網(wǎng)站電商網(wǎng)站建設(shè)價(jià)格
  • 網(wǎng)站內(nèi)容建設(shè)的原則是什么意思百度的企業(yè)網(wǎng)站
  • 上海企業(yè)建設(shè)網(wǎng)站成人職業(yè)技術(shù)培訓(xùn)學(xué)校
  • 個(gè)人網(wǎng)頁設(shè)計(jì)大全廈門seo排名優(yōu)化
  • 長治網(wǎng)站建設(shè)收費(fèi)多少2022最好的百度seo
  • 上海百度地圖百度快速seo軟件
  • 網(wǎng)站建設(shè)優(yōu)化文章重慶今日頭條新聞消息
  • 石家莊免費(fèi)做網(wǎng)站杭州seo公司
  • 哈爾濱做設(shè)計(jì)和網(wǎng)站的公司嗎電話營銷外包公司
  • 地方門戶網(wǎng)站模板seo教程seo優(yōu)化
  • 網(wǎng)頁制作模板的含義和作用在線seo工具
  • 簡單介紹網(wǎng)站建設(shè)的一般流程專業(yè)公司網(wǎng)絡(luò)推廣
  • 網(wǎng)站seo建設(shè)方案浙江seo推廣
  • 網(wǎng)站建設(shè)費(fèi) 科目天津網(wǎng)站排名提升多少錢
  • 網(wǎng)站宣傳方案網(wǎng)絡(luò)推廣長沙網(wǎng)絡(luò)推廣
  • 商城網(wǎng)站備案做網(wǎng)站哪家公司比較好而且不貴
  • 做購物網(wǎng)站適合的服務(wù)器站長工具國色天香
  • 政務(wù)網(wǎng)站集約化建設(shè)難點(diǎn)與建議湖南關(guān)鍵詞優(yōu)化首選
  • 網(wǎng)站導(dǎo)航css代碼培訓(xùn)課
  • 做高級(jí)電工題的網(wǎng)站外鏈工具在線
  • 校園互動(dòng)網(wǎng)站建設(shè)站長工具同大全站
  • 食品營銷網(wǎng)站建設(shè)調(diào)查問卷免費(fèi)網(wǎng)站流量統(tǒng)計(jì)工具
  • 做汽配找哪個(gè)網(wǎng)站好軟件排名工具
  • ruby 做網(wǎng)站谷歌推廣公司哪家好
  • 長沙手機(jī)網(wǎng)站建設(shè)哪些內(nèi)容建網(wǎng)站需要什么條件
  • icp網(wǎng)站備案系統(tǒng)中國最好的營銷策劃公司