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 就能默认带上以上参数去执行了