Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging of passthrus when there's no match #505

Merged
merged 2 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions responses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,11 @@ def _on_request(self, adapter, request, **kwargs):
m.method, m.url, match_failed_reasons[i]
)

if self.passthru_prefixes:
error_msg += "Passthru prefixes:\n"
for p in self.passthru_prefixes:
error_msg += "- {}\n".format(p)

response = ConnectionError(error_msg)
response.request = request

Expand Down
2 changes: 2 additions & 0 deletions responses/test_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1817,13 +1817,15 @@ def run():
with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps:
rsps.add("POST", "http://example1.com")
rsps.add("GET", "http://example.com")
rsps.add_passthru("http://other.example.com")

with pytest.raises(ConnectionError) as excinfo:
requests.post("http://example.com", data={"id": "bad"})

msg = str(excinfo.value)
assert "- POST http://example1.com/ URL does not match" in msg
assert "- GET http://example.com/ Method does not match" in msg
assert "Passthru prefixes:\n- http://other.example.com" in msg

run()
assert_reset()
Expand Down