Report Number Of Assertions In Pytest
Solution 1:
As far as I can see there is no such possibility to get the number of passed assertions out of pytest.
Reason: it employs Python's standard assert
statement, so the determination whether the assertion is a pass or a fail is done within the engine used, and in case the engine does not count how often it got into the "pass" branch of the necessary if
in assert
's implementation, and offer a way to read out that counter, there is just no way to elicit that information from the engine. So pyTest can't tell you that either.
Many (unit) test frameworks report assertion count by default, and IMHO i deem it desirable, because it is - amongst others - a measure for test quality: sloppy tests might apply too few checks to values.
Solution 2:
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.
Post a Comment for "Report Number Of Assertions In Pytest"