精品伊人久久大香线蕉,开心久久婷婷综合中文字幕,杏田冲梨,人妻无码aⅴ不卡中文字幕

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
PyTest Xfail /跳過測試

在某些情況下,我們不想執(zhí)行測試,或者在特定時(shí)間內(nèi)測試案例不相關(guān)。在這種情況下,我們可以選擇xfail測試或跳過測試

xfailed測試將被執(zhí)行,但不會(huì)被視為部分失敗或通過的測試。如果該測試失敗,將不會(huì)顯示任何回溯。我們可以使用xfail測試

@ pytest.mark.xfail。

跳過測試意味著將不會(huì)執(zhí)行測試。我們可以使用跳過測試

@ pytest.mark.skip。

使用以下代碼編輯test_addition.py

import pytest@pytest.mark.skipdef test_add_1(): assert 100+200 == 400,"failed"
@pytest.mark.skipdef test_add_2(): assert 100+200 == 300,"failed"
@pytest.mark.xfaildef test_add_3(): assert 15+13 == 28,"failed"
@pytest.mark.xfaildef test_add_4(): assert 15+13 == 100,"failed"
def test_add_5(): assert 3+2 == 5,"failed"
def test_add_6(): assert 3+2 == 6,"failed"

這里

  • test_add_1和test_add_2被跳過,將不會(huì)執(zhí)行。

  • test_add_3和test_add_4失敗。這些測試將被執(zhí)行,并將成為xfailed(測試失敗)或xpassed(測試通過)測試的一部分。不會(huì)有任何失敗的回溯。

  • 當(dāng)test_add_5通過時(shí),將執(zhí)行test_add_5和test_add_6,并且test_add_6將報(bào)告失敗并進(jìn)行追溯

通過py.test test_addition.py -v執(zhí)行測試并查看結(jié)果

test_addition.py::test_add_1 SKIPPEDtest_addition.py::test_add_2 SKIPPEDtest_addition.py::test_add_3 XPASStest_addition.py::test_add_4 xfailtest_addition.py::test_add_5 PASSEDtest_addition.py::test_add_6 FAILED
============================================== FAILURES ==============================================_____________________________________________ test_add_6 _____________________________________________ def test_add_6():> assert 3+2 == 6,"failed"E AssertionError: failedE assert (3 + 2) == 6test_addition.py:24: AssertionError
================ 1 failed, 1 passed, 2 skipped, 1 xfailed, 1 xpassed in 0.07 seconds =================

結(jié)果XML

我們可以創(chuàng)建XML格式的測試結(jié)果,并將其提供給Continuous Integration服務(wù)器進(jìn)行進(jìn)一步處理,等等。這可以通過

py.test test_sample1.py -v --junitxml =“ result.xml”

result.xml將記錄測試執(zhí)行結(jié)果。在下面找到一個(gè)示例result.xml

<?xml version="1.0" encoding="UTF-8"?><testsuite errors="0" failures="1" name="pytest" skips="0" tests="2" time="0.046"> <testcase classname="test_sample1" file="test_sample1.py" line="3" name="test_file1_method1" time="0.001384973526"> <failure message="AssertionError:test failed because x=5 y=6 assert 5 ==6"> @pytest.mark.set1 def test_file1_method1(): x=5 y=6 assert x+1 == y,"test failed"> assert x == y,"test failed because x=" + str(x) + " y=" + str(y)E AssertionError: test failed because x=5 y=6E assert 5 == 6 test_sample1.py:9: AssertionError </failure> </testcase> <testcase classname="test_sample1" file="test_sample1.py" line="10" name="test_file1_method2" time="0.000830173492432" /></testsuite>

從<testsuite errors =“ 0” failures =“ 1” name =“ pytest” skips =“ 0” tests =“ 2” time =“ 0.046”>中,我們可以看到總共兩個(gè)測試,其中一個(gè)失敗。在下面,您可以在<testcase>標(biāo)記下查看有關(guān)每個(gè)已執(zhí)行測試的詳細(xì)信息。

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
pytest文檔12-skip跳過用例
pytest文檔51-內(nèi)置fixture之cache使用
Python  pytest快速入門
python-如何使用py.test對多個(gè)項(xiàng)目執(zhí)行多個(gè)測試
Flask項(xiàng)目發(fā)布流程
Python 單元測試框架:Pytest
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

主站蜘蛛池模板: 紫阳县| 富源县| 孟村| 古浪县| 资兴市| 宁都县| 社旗县| 嘉兴市| 财经| 庄浪县| 青冈县| 石河子市| 丹江口市| 肃南| 余干县| 格尔木市| 闽清县| 盱眙县| 元朗区| 张家口市| 炎陵县| 玉林市| 庆城县| 疏勒县| 通榆县| 商丘市| 荣成市| 宾川县| 若羌县| 留坝县| 澳门| 微博| 惠水县| 阜康市| 昭通市| 定结县| 延安市| 斗六市| 砚山县| 林芝县| 甘肃省|