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

Sylvain Viart sylvain at opensource-expert.com
Wed Nov 2 04:46:30 PDT 2016


I didn't find the answer yet, but I tested another approach with httmock


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.


Nothing under this citation, new version has been commited, links may be
> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20161102/b3f441be/attachment.html>

More information about the testing-in-python mailing list