安装
pip install -U pytest;
使用方法
代码示例:
导入py测试
deftest_a(:
打印(testa ) )。
资产1 #成功
deftest_b(:
打印(testb ) ) ) )。
资产0 #失败
if __name__=='__main__':
pytest.main(['-s ',' test_pytest.py']
输出结果:
py测试退出代码的语义列表
Exit code 0的所有用例都已运行并全部通过
Exit code 1的所有用例都已运行,并且存在故障测试用例
Exit code 2用户中断了测试的执行
执行Exit code 3测试时发生内部错误
使用Exit code 4 pytest命令行时出错
Exit code 5无法收集可用的测试用例文件
生成测试报告
1安装报告生成插件pytest-HTML
pip安装py test-html
2运行报告生成命令
pytest --html=./report.html
3在目录下生成assert目录和report.html结果报告文件