pythonintegration-testingpytest

Report number of assertions in 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.


Solution

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

    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.