pytest icon indicating copy to clipboard operation
pytest copied to clipboard

`pytest_assertrepr_compare` hook should take the same arguments as `pytest_assertion_pass`

Open DetachHead opened this issue 1 year ago • 1 comments

What's the problem this feature will solve?

in my plugin (pytest-robotframework), i want to be able to log both passing and failing assertions in the same way, as a keyword in the robot log with the original expression from the assert statement. for example, the following test would produce this output in the robot log:

def test_foo():
    left = 1
    right = 1
    assert left == right

265295074-c2525ccf-c1c6-4c06-be79-c36fefd3bed4

however i can't do that with failing assertions, because pytest_assertrepr_compare does not have an orig argument, so only the actual values can be displayed, not the original left == right expression from the assert statement:

image

Describe the solution you'd like

either:

  1. add the orig argument from pytest_assertion_pass to pytest_assertrepr_compare. the other arguments would be useful too: item, lineno, expl (expl would be the default explanation or the explanation returned from a previous hook)
  2. create a new pytest_assertion_fail hook that takes the same arguments as pytest_assertion_pass

DetachHead avatar Feb 15 '24 22:02 DetachHead

This would also be useful for safety critical testing where a formal review of the outputs needs to occur.

Sillocan avatar Jun 03 '24 18:06 Sillocan