[TIP] py.test + mock - how to test attribute "call"?

Daniel Bradburn moagstar at gmail.com
Wed Nov 2 11:10:56 PDT 2016


Hi Sylvain, perhaps the responses library might be of use to you for
mocking the requests library

https://pypi.python.org/pypi/responses

Regards
Dan

On Nov 2, 2016 12:50 PM, "Sylvain Viart" <sylvain at opensource-expert.com>
wrote:

> Hi,
>
> I didn't find the answer yet, but I tested another approach with httmock
> package.
>
>
> https://github.com/opensource-expert/powerdns-shell-wrapper/
> blob/dev-override-cmd-line/test/test_pdns_zone.py#L73
>
> I also gonna explore setting up an instance of powerdns to have a fully
> testable environment.
>
> I you still have mocking / testing suggestion I'm interested.
>
> Regards,
> Sylvain.
>
> Nothing under this citation, new version has been commited, links may be
> wrong.
>
> I'm having trouble to understand how to use correctly mock object to test
> correctness of requests' call and also returned object.
>
> I'm using py.test + pytest-mock
>
> I would like to test here that r.text is returned if I call:
> r = p.exec_pdns_api('GET', rest_url, text=True)
> https://github.com/opensource-expert/powerdns-shell-wrapper/
> blob/dev-override-cmd-line/pdns_zone.py#L79
>
> how to I make an assertion that the r.text has been called/returned?
>
> r is <MagicMock name='get().text' id='139703066450704'>
>
> r.text.assert_called() is not the good assertion
> test code here: https://github.com/opensource-
> expert/powerdns-shell-wrapper/blob/dev-override-cmd-line/
> test/test_pdns_zone.py#L40
>
>
> --
> Sylvain Viart - DevOps système linux - freelance developer
>
>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20161102/954566cd/attachment.htm>


More information about the testing-in-python mailing list