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

Joep Schuurkes j19sch at gmail.com
Thu Jun 13 06:28:33 EDT 2019


Not sure if this would work for your setup, but we solved that by defining
a generic api client class with a logging method that's added to the hooks
on the response object of the requests library. Each specific api client
class then inherits from the generic one.

Regards,
Joep

On Thu, Jun 13, 2019, 12:19 Craig de Stigter <craig.ds at gmail.com> wrote:

> Thanks for the replies.
>
> We do already use the print-before-assert pattern. It'd be nice to be able
> to fold this away in a hook so each individual request test doesn't need to
> think about it. But using print() is perfectly fine too :)
>
>
>
>
> On Thu, 13 Jun 2019 at 19:35, Joep Schuurkes <j19sch at gmail.com> wrote:
>
>> Hi,
>>
>> On Thu, Jun 13, 2019, 10:25 Florian Bruhin <me at the-compiler.org> wrote:
>>
>>> Hey,
>>>
>>> On Thu, Jun 13, 2019 at 12:02:01PM +1200, Craig de Stigter wrote:
>>> > 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.
>>>
>>> It'd be cool if this were possible with hooks (I'm not sure whether it
>>> is) -
>>> but FWIW, what I've done so far in such situations is "print(r.content)"
>>> in the
>>> test. That way, pytest shows you the output when a test failed, but
>>> hides it
>>> for passing tests.
>>>
>>> Florian
>>>
>>> --
>>> https://www.qutebrowser.org | me at the-compiler.org (Mail/XMPP)
>>>    GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
>>>          I love long mails! | https://email.is-not-s.ms/
>>> _______________________________________________
>>> pytest-dev mailing list
>>> pytest-dev at python.org
>>> https://mail.python.org/mailman/listinfo/pytest-dev
>>
>>
>> We use logging similar to the print mentioned by Florian. I also created
>> a pytest plugin to have some options for how the generated logs are written
>> to file: https://pypi.org/project/pytest-logfest/
>>
>> Regards,
>> Joep
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20190613/255c3fc3/attachment.html>


More information about the pytest-dev mailing list