草庐IT

python - 如何通过检查传递给 pytest_runtest_teardown 的 Item 对象来确定测试是通过还是失败?

Pytest允许您通过在插件中实现一个名为pytest_runtest_teardown的函数来Hook每个测试的拆解阶段:defpytest_runtest_teardown(item,nextitem):passitem上是否有属性或方法可用于确定刚刚运行完的测试是通过还是失败?我找不到关于pytest.Item的任何文档,并且搜索源代码并在ipdb中游玩没有发现任何明显的东西。 最佳答案 你也可以考虑pytest_runtest_makereport中的call.excinfo:defpytest_runtest_makere