Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
side_effect=ConnectionRefusedError("test request blocked"),
) as open_connection:
with pytest.raises(NetworkError):
await client.get("https://example.org/")
assert open_connection.called is True
assert request.called is True
assert request.pass_through is expected
with MockTransport() as respx_mock:
request = respx_mock.add(**parameters)
with asynctest.mock.patch(
"socket.socket.connect", side_effect=socket.error("test request blocked"),
) as connect:
with pytest.raises(NetworkError):
httpx.get("https://example.org/")
assert connect.called is True
assert request.called is True
assert request.pass_through is expected
async def test_pass_through(client, parameters, expected):
async with MockTransport() as respx_mock:
request = respx_mock.add(**parameters)
with asynctest.mock.patch(
"asyncio.open_connection",
side_effect=ConnectionRefusedError("test request blocked"),
) as open_connection:
with pytest.raises(NetworkError):
await client.get("https://example.org/")
assert open_connection.called is True
assert request.called is True
assert request.pass_through is expected
with MockTransport() as respx_mock:
request = respx_mock.add(**parameters)
with asynctest.mock.patch(
"socket.socket.connect", side_effect=socket.error("test request blocked"),
) as connect:
with pytest.raises(NetworkError):
httpx.get("https://example.org/")
assert connect.called is True