pytest执行case

Python测试套件:pytest

一、case执行:

通过命令:

1、python -m pytests [...]

2、pytest [...](需要注意环境变量)

 

在文件中调用:

pytest.main()

pytest.main(["-x", "mytestdir"])

 

二、pytest运行退出code说明:

Exit code 0  所有cases都被发现收集且运行通过;

Exit code 1  所有cases都被发现收集但部分运行通过;

Exit code 2  运行被用户中断(比如执行pytest过程中,用户使用了Ctrl+c);

Exit code 3  执行cases的时候发生了内部错误;

Exit code 4  pytest命令行使用错误;

Exit code 5  没有发现任何测试集。

如果你想在脚本中定制Exit code,可以使用pytest-custom_exit_code plugin.

 

三、pytest命令选项说明:

pytest --version # shows where pytest was imported from
pytest --fixtures # show available builtin function arguments
pytest -h | --help # show help on command line and config file options

pytest -x # stop after first failure
pytest --maxfail=2 # stop after two failures

 

四、pytest运行范围

1、运行一个模块(一个py脚本文件) pytest test_mod.py

2、运行一个目录下的cases:pytest testing/

3、通过关键字运行cases:pytest -k "MyClass and not method"

4、通过节点id运行cases:

    pytest test_mod.py::test_func 运行一个模块中特定的方法

    pytest test_mod.py::TestClass::test_method 运行一个模块中TestClass中的test_method 方法

5、通过标记运行cases:pytest -m slow 运行有@pytest.mark.slow装饰器的方法

 

五、失败cases调试pytest --pdb

pytest -x --pdb # drop to PDB on first failure, then end test session
pytest --pdb --maxfail=3 # drop to PDB for first three failures
Note that on any failure the exception information is stored on sys.last_value, sys.

 

六、生成测试结果

1、生成XML文件 pytest --junitxml=path

2、生成html文件  pytest --html=path/XX.html

 

参考文档:pytest.pdf

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值