Open hf-kklein opened 1 year ago
Had the same problem and resolved it by adding response_class like below:
with aioresponses() as mocked:
mocked.post("https://myserver.inv/", status=500, payload="terrible crash", response_class=MyClientResponse)
@p2vvel So you mean: Adding the response class to the actual request instead of to the session is a workaround, right?
Yes, I managed to use custom raise_for_status()
during testing with aioresponses
that way.
I'm using the following code, which preserves the response body in case
raise_for_status=True
. I copied it from https://github.com/aio-libs/aiohttp/issues/4600#issuecomment-922520737 and it works in reality but not when testing with aioresponses:I cannot point my finger on it. Might be my test setup is wrong but I feel like this is an error/missing feature of aioresponses, because, as I said, it works with a real server but not with a mocked one.