Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change error and failure detection in pytest?

In pytest, I want to report all uncaught AssertionError exceptions as Failure and all other uncaught exceptions as Errors (instead of the default behavior of reporting all uncaught exceptions in setup method as Errors while all uncaught exceptions in test cases and UUT as Failure). I thought it could be done with pytest hooks. However, "passed", "skipped", and "failed" seem to be the only valid outcome values in TestReport object.

So,

  1. Is it possible to add "error" as a valid outcome and let the rest of pytest do the appropriate reporting, i.e., display E/ERROR instead of F/FAILURE on console output?
  2. If so, what would be the ideal part of the source to do this?
  3. If we cannot add "error" as a valid outcome, then what would be the best way to inject this behavior?
like image 260
Venkatesh-Prasad Ranganath Avatar asked Dec 05 '25 07:12

Venkatesh-Prasad Ranganath


1 Answers

[Self answer]

pytest-finer-verdicts plugin achieves this behavior :)

like image 177
Venkatesh-Prasad Ranganath Avatar answered Dec 07 '25 21:12

Venkatesh-Prasad Ranganath