pnuckowski/aioresponses

No way of passthrough non matching urls

sunbit opened this issue · 1 comments

I hit a use case where i want to mock a series of urls, and passthrough any other url, instead of the current behaviour that is raising a ClientConnectionError. The use case is ignoring urls for docker container fixtures, that depending on the environment is different.

I think this is a valid use case, and i don't see a way to do it right now, this is what i tried:

  • adding a generic passthrough="http://, but as it hits before matching the actual mocks it's not usable.
  • adding a rule with a negative lookbehind regex, but i cannot execute the original request from the callback context.

At the end i solved it by capturing the docker fixtures urls and using the passthrough option, but it adds unnecessary complexity to the tests.

I propose a couple solutions, that i can provide a PR for, just want to discuss it if possible:

  • Adding a flag to change the default behaviour, "passthrough_unmatched", defaulting to False to preserve the current behaviour
  • Allow passing compiled regexes as passthrough urls

Which one do you think could be better? I'm inclined to the first one

gmaze commented

This would be very useful !
👍🏻 for #233