0二、pytest经常使用命令行选项

能够使用 -v 选项,显示测试的详细信息。html

pytest -v demo.py
=================================================== test session starts ====================================================
platform darwin -- Python 3.7.4, pytest-4.4.0, py-1.8.0, pluggy-0.13.0 -- /Users/zhouwanghua/Code/Leyan/python/robocop/bin/python
cachedir: .pytest_cache
metadata: {'Python': '3.7.4', 'Platform': 'Darwin-18.6.0-x86_64-i386-64bit', 'Packages': {'pytest': '4.4.0', 'py': '1.8.0', 'pluggy': '0.13.0'}, 'Plugins': {'bdd': '3.1.0', 'html': '1.20.0', 'metadata': '1.8.0'}}
rootdir: /Users/zhouwanghua/Code/Leyan/robocop, inifile: pytest.ini
plugins: bdd-3.1.0, html-1.20.0, metadata-1.8.0
collected 1 item                                                                                                           

demo.py::test_demo PASSED

经常使用命令行选项

pytest有丰富的命令行选项,以知足不一样的须要,下面对经常使用的命令行选项做下简单介绍。 上文已经使用过-v选项,还有不少选项,你能够使用pytest --help查看所有选项.以下图:python

Command Desc
pytest --help 显示所有选项
pytest --collect-only 给定配置下显示那些用例会运行
pytest -k "asdict or defaults" --collect-only 筛选用例
pytest -x 遇到失败后中止测试
pytest --tb=no 关闭错误信息回溯argument --tb: (choose from 'short', 'no', 'line')
pytest --maxfail=2 --tb=no 明确指定失败几回后中止
pytest -s(pytest --capture=no) 信息捕获方法pytest --capture=sys和pytest --capture=fd
pytest -l(pytest --showlocals) 避免一些没必要要的print语句
pytest -lf --tb=no 定位到最后一个失败的用例
pytest -ff --tb=no 定位到第一个失败的用例,ff会运行完剩余的用例
pytest -v --ff --tb=no 每一个用例占一行(以前是每一个文件占一行)
pytest -q 简化输出信息
pytest -l 打印本地变量
pytest --duration=3 显示耗时最长的三个阶段
pytest --version 查看pytest版本及安装目录
相关文章
相关标签/搜索