报告pyTest中的断言数量 [英] Report number of assertions in pyTest

查看:70
本文介绍了报告pyTest中的断言数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 pytest 在集成级别编写一些测试.我还希望能够报告在每个测试用例上完成的断言数量.默认情况下, pytest 仅报告已通过和失败的测试用例的数量.

I am using pytest for writing some tests at integration level. I would like to be able to also report the number of assertions done on each test case. By default, pytest will only report the number of test cases which have passed and failed.

推荐答案

在断言时,测试的进一步执行将中止.因此,每个测试始终会有1个断言.

On assertion further execution of test is aborted. So there will always be 1 assertion per test.

要实现您想要的目标,您将必须在断言上编写自己的包装器以进行跟踪.在测试结束时,检查count是否大于0,然后引发断言.可以在 setup 或测试的 teardown 处将计数重置为零.

To achieve what you want you will have to write your own wrapper over assertion to keep track. At the end of the test check if count is >0 then raise assertion. The count can be reset to zero either the setup or at teardown of test.

这篇关于报告pyTest中的断言数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆