Skip to content

Commit 4c4b46b

Browse files
tests: wrap passthru inside another mock (#495)
* wrap passthru inside another mock * Update responses/test_responses.py Co-authored-by: Mark Story <mark@mark-story.com>
1 parent 930b784 commit 4c4b46b

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

responses/test_responses.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,14 +1661,14 @@ def test_passthru_does_not_persist_across_tests(httpserver):
16611661
def with_a_passthru():
16621662
assert not responses._default_mock.passthru_prefixes
16631663
responses.add_passthru(re.compile(".*"))
1664-
try:
1665-
response = requests.get("https://example.com")
1666-
except ConnectionError as err: # pragma: no cover
1667-
if "Failed to establish" in str(err): # pragma: no cover
1668-
pytest.skip("Cannot resolve DNS for example.com") # pragma: no cover
1669-
raise err # pragma: no cover
1670-
1671-
assert response.status_code == 200
1664+
1665+
# wrap request that is passed through with another mock. That helps
1666+
# to avoid issues if real URL is unavailable, allow to run tests offline
1667+
with responses.RequestsMock(target="responses._real_send") as rsp:
1668+
rsp.add(responses.GET, "https://example66.ru", status=969)
1669+
response = requests.get("https://example66.ru")
1670+
1671+
assert response.status_code == 969
16721672

16731673
@responses.activate
16741674
def without_a_passthru():

0 commit comments

Comments
 (0)