pytest-assume icon indicating copy to clipboard operation
pytest-assume copied to clipboard

Display expected and actual for failed assumes

Open mcarans opened this issue 8 years ago • 7 comments

Is there any way for each failed assume to display what was expected and what the actual result was?

mcarans avatar Jan 20 '17 12:01 mcarans

That was my original goal when I was working on this, but it's not really feasible unless I use what pytest itself does with assertions. They re-write the modules, breaking down each assert into parts for use with display, then asserting. You can see some of that here, and it's really not an easy thing to replicate (or reuse).

astraw38 avatar Jan 20 '17 14:01 astraw38

Ok thanks, it's a shame, but appreciate you have made the effort to investigate.

mcarans avatar Jan 20 '17 15:01 mcarans

_pytest.assertion.rewrite seems to have moved since @astraw38 linked to it in January 2017.

akaihola avatar Oct 09 '18 11:10 akaihola

Updated location: https://github.com/pytest-dev/pytest/blob/3.8.2/src/_pytest/assertion/rewrite.py (with a tagged release, rather than off the master, which could be subject to the same problem in the future)

astraw38 avatar Oct 09 '18 13:10 astraw38

@mcarans using assume as a context manager retains the pytest generated explanations, as you will still be having the assert keyword and those will naturally be rewritten by pytest.

Sup3rGeo avatar Jul 31 '19 09:07 Sup3rGeo

@Sup3rGeo Do you mean use this form:

    with assume: assert x == y
    with assume: assert True
    with assume: assert False

?

mcarans avatar Jul 31 '19 10:07 mcarans

Yes!

Sup3rGeo avatar Jul 31 '19 10:07 Sup3rGeo