xfail_strict
先接觸下@pytest.mark.xfail
這個的用法,簡單理解就是預測用例會執行失敗,最後執行失敗後,執行demo和結果顯示如下:
@pytest.mark.xfail()
def test_s1():
print ('case 1,登錄後其他動作111')
assert 1==2
test_fix.py xcase 1,登錄後其他動作111
@pytest.mark.xfail()
def test_s1():
print ('case 1,登錄後其他動作111')
> assert 1==2
E assert 1 == 2
test_fix.py:15: AssertionError
[100%]
========================== 1 xfailed in 0.13 seconds ==========================
預測失敗,最後執行也失敗的,顯示未xfailed,那如果預測失敗,結果執行成功了呢
@pytest.mark.xfail()
def test_s1():
print ('case 1,登錄後其他動作111')
assert 1==1
plugins: allure-pytest-2.8.6, html-2.0.1, metadata-1.8.0, rerunfailures-8.0collected 1 item
test_fix.py Xcase 1,登錄後其他動作111
[100%]
========================== 1 xpassed in 0.02 seconds ==========================
預測失敗,最後執行居然成功了,結果顯示成了1xpassed了。
如果再實際應用中,你預測要失敗的,執行還成功,那我們的理解就是這個用例執行是有問題的,我們應該將這個用例顯示爲失敗。這時候就要在pytest.ini中配置一個參數了
xfail_strict =true。這樣配置後,預計失敗(xfailed),結果成功的(xpassed),就會直接顯示爲失敗了(failed)
*pytest.ini*
[pytest]
addopts = --strict-markers
markers =
zhou: marks tests
s1erial: test1
xfail_strict = true
@pytest.mark.xfail()
def test_s1():
print ('case 1,登錄後其他動作111')
assert 1==1
================================== FAILURES ===================================
___________________________________ test_s1 ___________________________________
[XPASS(strict)]
---------------------------- Captured stdout call -----------------------------
case 1,登錄後其他動作111
========================== 1 failed in 0.02 seconds ===========================
addopts
用於修改默認命令行
比如我們平時用於生成測試報告的指令爲
pytest -v --rerun 1 --html=report.html --self-contained-html
此項命令行太長,不容易記住,我們就可以把它加入到pytest.ini裏面,
[pytest]
addopts = -v --rerun 1 --html=report.html --self-contained-html
這樣,下次直接在cmd下面輸入 pytest 就能默認帶上以上參數去執行了