pytest.ini配置项说明xfail_strict、addopts

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值