[pytest-dev] Customising repr() output for super-expressions of failed assertions

Craig de Stigter craig.ds at gmail.com
Wed Jun 12 20:02:01 EDT 2019

Hi there

Considering this failed assertion where a django test request failed:

>       assert r.status_code == 201
E       assert 400 == 201
E         -400
E         +201

This output isn't terribly useful at present. We'd like to automatically
dump the request body (`r.content`) in the output, wherever it's a django
response object, to aid debugging.

I see the `pytest_assertrepr_compare` hook gets passed the top-level
objects and the operator for writing a custom message. However if I'm
reading it right there's no way to access the containing expression there
(i.e. `r`) and treat it specially.

Is there a way to do this using pytest's hooks?

Craig de Stigter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20190613/42664cd9/attachment.html>

More information about the pytest-dev mailing list