上一节我们介绍了pytest的安装和简单使用,这一节我们再加些料
pytest不仅容易编写小的测试例,也支持程序和库相关的复杂函数测试
通过python -m pytest来调用pytest
python -m pytest [...]
这和直接使用pytest命令功能相同,唯一的区别是会将当前目录加入到sys.path中.
可能的退出码
调用pytest可能产生6种不同的退出码
Exit code 0: | 所有的测试例都被收集且通过 |
---|---|
Exit code 1: | 所有的测试例都被收集但有部分失败 |
Exit code 2: | 测试例执行被用户中断 |
Exit code 3: | 发生了内部错误 |
Exit code 4: | pytest命令行使用错误 |
Exit code 5: | 没用收集到测试例 |
pytest的退出码API
from pytest import ExitCode
如果你需要在某些场景下定制ExiCode,可以使用pytest-custom_exit_code插件
pytest帮助命令
<