Colin-b/pytest_httpx

httpx.Response.elapsed cannot be accessed anymore

Closed this issue · 5 comments

mvbrn commented

I have logging that reads request time from .elapsed attribute of httpx.Request. Everything works with 0.13, but after upgrading to 0.15 I'm getting exceptions:

'.elapsed' may only be accessed after the response has been read or closed.

My versions:
httpx==0.21.1
pytest-httpx==0.15.0

Hello @mvbrn , would you mind sharing your code?
This issue seems to be related to httpx (from what you are saying, you bumped httpx from 0.19 to 0.21), are you sure your code works without the mock? ie: does it work in real condition?
Thanks again

I confirm that I am able to reproduce your issue.

Fixed in release 0.17.1. Thanks for reporting @mvbrn

mvbrn commented

Unfortunately, it was fixed only for add_response and still does not work for add_callback. I've proposed a fix -> #61

Thanks @mvbrn ,

Release 0.17.2 was performed today with your fix