Python "responses library: no match for registered URL" in CI
The responses library raises a ConnectionError when code makes an HTTP request that does not match any registered mock. The message lists the unmatched request and the registered responses so you can see the mismatch.
What this error means
A test fails with "requests.exceptions.ConnectionError: Connection refused by Responses - the call doesn't match any registered mock" and a diff of requested vs registered URLs.
pytest
ConnectionError: Connection refused by Responses - the call doesn't match any registered mock.
Request: - GET https://api.example.com/v2/items
Registered responses: - GET https://api.example.com/v1/itemsCommon causes
No mock registered for the exact URL/method
The code calls a URL (or method, or query string) that no registered response matches.
A path, query, or body matcher mismatch
A registered response targets a slightly different path or requires a matcher the request does not satisfy.
How to fix it
Register a matching response or relax the matcher
- Register a response for the exact method and URL the code calls.
- Use match parameters (query string, body) only when needed, and align them with the request.
- Enable assert_all_requests_are_fired to catch unused/missing mocks.
Python
import responses
@responses.activate
def test_items():
responses.add(responses.GET, "https://api.example.com/v2/items", json=[], status=200)
...How to prevent it
- Register mocks for every endpoint the code under test calls.
- Keep mock URLs in sync with the client code.
- Use assert_all_requests_are_fired to find drift.
Related guides
Python "moto mock not patching boto3" in CIFix moto mocks that do not patch boto3 in CI - real AWS calls leak through because the client was created out…
Python "pytest-cov: no data was collected" in CIFix "CoverageWarning: No data was collected" with pytest-cov in CI - coverage measured nothing, usually a wro…
responses / VCR "Connection refused" - Cassette Not Matched in CIFix responses/VCR.py "ConnectionError" / "no cassette" in CI - an unmatched request hits the network because…