Skip to content
Myr

Clean up 'backend' fixture (#664)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Clean up 'backend' fixture * Add docstring to 'async_environment' fixture

authored by Florimond Manca · committed by GitHub · parent 56c8eda · Browse files · 9 files+164 added−114 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

9 files+164 added−114 removed

  • tests:+164 added−114 removed

9 files+164 added−114 removed

modified:tests/client/test_async_client.py+32 added-39 removed
3 unmodified lines
45import httpx678@pytest.mark.usefixtures("async_environment")8async def test_get(server, backend):9async def test_get(server):10 url = server.url11 async with httpx.Client() as client:12 response = await client.get(url)13 assert response.status_code == 200
3 unmodified lines
17 assert repr(response) == "<Response [200 OK]>"18 assert response.elapsed > timedelta(seconds=0)192021@pytest.mark.usefixtures("async_environment")20async def test_build_request(server, backend):22async def test_build_request(server):23 url = server.url.copy_with(path="/echo_headers")24 headers = {"Custom-header": "value"}25 async with httpx.Client() as client:26 request = client.build_request("GET", url)
5 unmodified lines
3233 assert response.json()["Custom-header"] == "value"343534@pytest.mark.asyncio35async def test_get_no_backend(server):36 """37 Verify that the client is capable of making a simple request if not given a backend.38 """36@pytest.mark.usefixtures("async_environment")37async def test_post(server):38 url = server.url39 async with httpx.Client() as client:41 response = await client.get(url)42 assert response.status_code == 20043 assert response.text == "Hello, world!"44 assert response.http_version == "HTTP/1.1"45 assert response.headers46 assert repr(response) == "<Response [200 OK]>"474849async def test_post(server, backend):50 url = server.url51 async with httpx.Client() as client:40 response = await client.post(url, data=b"Hello, world!")41 assert response.status_code == 200424344@pytest.mark.usefixtures("async_environment")56async def test_post_json(server, backend):45async def test_post_json(server):46 url = server.url47 async with httpx.Client() as client:48 response = await client.post(url, json={"text": "Hello, world!"})49 assert response.status_code == 200505152@pytest.mark.usefixtures("async_environment")63async def test_stream_response(server, backend):53async def test_stream_response(server):54 async with httpx.Client() as client:55 async with client.stream("GET", server.url) as response:56 body = await response.read()57
1 unmodified line
59 assert body == b"Hello, world!"60 assert response.content == b"Hello, world!"616263@pytest.mark.usefixtures("async_environment")73async def test_access_content_stream_response(server, backend):64async def test_access_content_stream_response(server):65 async with httpx.Client() as client:66 async with client.stream("GET", server.url) as response:67 pass68
1 unmodified line
70 with pytest.raises(httpx.ResponseNotRead):71 response.content727374@pytest.mark.usefixtures("async_environment")83async def test_stream_request(server, backend):75async def test_stream_request(server):76 async def hello_world():77 yield b"Hello, "78 yield b"world!"79
1 unmodified line
81 response = await client.request("POST", server.url, data=hello_world())82 assert response.status_code == 200838485@pytest.mark.usefixtures("async_environment")93async def test_raise_for_status(server, backend):86async def test_raise_for_status(server):87 async with httpx.Client() as client:88 for status_code in (200, 400, 404, 500, 505):89 response = await client.request(90 "GET", server.url.copy_with(path=f"/status/{status_code}")
6 unmodified lines
97 else:98 assert response.raise_for_status() is None99100101@pytest.mark.usefixtures("async_environment")108async def test_options(server, backend):102async def test_options(server):103 async with httpx.Client() as client:104 response = await client.options(server.url)105 assert response.status_code == 200106 assert response.text == "Hello, world!"107108109@pytest.mark.usefixtures("async_environment")115async def test_head(server, backend):110async def test_head(server):111 async with httpx.Client() as client:112 response = await client.head(server.url)113 assert response.status_code == 200114 assert response.text == ""115116117@pytest.mark.usefixtures("async_environment")122async def test_put(server, backend):118async def test_put(server):119 async with httpx.Client() as client:120 response = await client.put(server.url, data=b"Hello, world!")121 assert response.status_code == 200122123124@pytest.mark.usefixtures("async_environment")128async def test_patch(server, backend):125async def test_patch(server):126 async with httpx.Client() as client:127 response = await client.patch(server.url, data=b"Hello, world!")128 assert response.status_code == 200129130131@pytest.mark.usefixtures("async_environment")134async def test_delete(server, backend):132async def test_delete(server):133 async with httpx.Client() as client:134 response = await client.delete(server.url)135 assert response.status_code == 200136 assert response.text == "Hello, world!"137138139@pytest.mark.usefixtures("async_environment")141async def test_100_continue(server, backend):140async def test_100_continue(server):141 headers = {"Expect": "100-continue"}142 data = b"Echo request body"143144 async with httpx.Client() as client:
4 unmodified lines
149 assert response.status_code == 200150 assert response.content == data151152153@pytest.mark.usefixtures("async_environment")154async def test_uds(uds_server, backend):154async def test_uds(uds_server):155 url = uds_server.url156 uds = uds_server.config.uds157 assert uds is not None158 async with httpx.Client(uds=uds) as client:
2 unmodified lines
161 assert response.text == "Hello, world!"162 assert response.encoding == "iso-8859-1"163164165@pytest.mark.parametrize(166 "backend",167 [168 pytest.param("asyncio", marks=pytest.mark.asyncio),169 pytest.param("trio", marks=pytest.mark.trio),170 ],171)172async def test_explicit_backend(server, backend):173 async with httpx.Client(backend=backend) as client:165async def test_explicit_backend(server, async_environment):166 async with httpx.Client(backend=async_environment) as client:167 response = await client.get(server.url)168 assert response.status_code == 200169 assert response.text == "Hello, world!"
modified:tests/client/test_redirects.py+40 added-20 removed
101 unmodified lines
102103 return Response(codes.OK, content=b"Hello, world!", request=request)104105106@pytest.mark.usefixtures("async_environment")106async def test_no_redirect(backend):107async def test_no_redirect():108 client = Client(dispatch=MockDispatch())109 url = "https://example.com/no_redirect"110 response = await client.get(url)111 assert response.status_code == 200112 with pytest.raises(NotRedirectResponse):113 await response.next()114115116@pytest.mark.usefixtures("async_environment")115async def test_redirect_301(backend):117async def test_redirect_301():118 client = Client(dispatch=MockDispatch())119 response = await client.post("https://example.org/redirect_301")120 assert response.status_code == codes.OK121 assert response.url == URL("https://example.org/")122 assert len(response.history) == 1123124125@pytest.mark.usefixtures("async_environment")123async def test_redirect_302(backend):126async def test_redirect_302():127 client = Client(dispatch=MockDispatch())128 response = await client.post("https://example.org/redirect_302")129 assert response.status_code == codes.OK130 assert response.url == URL("https://example.org/")131 assert len(response.history) == 1132133134@pytest.mark.usefixtures("async_environment")131async def test_redirect_303(backend):135async def test_redirect_303():136 client = Client(dispatch=MockDispatch())137 response = await client.get("https://example.org/redirect_303")138 assert response.status_code == codes.OK139 assert response.url == URL("https://example.org/")140 assert len(response.history) == 1141142143@pytest.mark.usefixtures("async_environment")139async def test_disallow_redirects(backend):144async def test_disallow_redirects():145 client = Client(dispatch=MockDispatch())146 response = await client.post(147 "https://example.org/redirect_303", allow_redirects=False148 )
8 unmodified lines
157 assert response.is_redirect is False158 assert len(response.history) == 1159160161@pytest.mark.usefixtures("async_environment")156async def test_relative_redirect(backend):162async def test_relative_redirect():163 client = Client(dispatch=MockDispatch())164 response = await client.get("https://example.org/relative_redirect")165 assert response.status_code == codes.OK166 assert response.url == URL("https://example.org/")167 assert len(response.history) == 1168169170@pytest.mark.usefixtures("async_environment")164async def test_no_scheme_redirect(backend):171async def test_no_scheme_redirect():172 client = Client(dispatch=MockDispatch())173 response = await client.get("https://example.org/no_scheme_redirect")174 assert response.status_code == codes.OK175 assert response.url == URL("https://example.org/")176 assert len(response.history) == 1177178179@pytest.mark.usefixtures("async_environment")172async def test_fragment_redirect(backend):180async def test_fragment_redirect():181 client = Client(dispatch=MockDispatch())182 response = await client.get("https://example.org/relative_redirect#fragment")183 assert response.status_code == codes.OK184 assert response.url == URL("https://example.org/#fragment")185 assert len(response.history) == 1186187188@pytest.mark.usefixtures("async_environment")180async def test_multiple_redirects(backend):189async def test_multiple_redirects():190 client = Client(dispatch=MockDispatch())191 response = await client.get("https://example.org/multiple_redirects?count=20")192 assert response.status_code == codes.OK193 assert response.url == URL("https://example.org/multiple_redirects")
7 unmodified lines
201 assert len(response.history[0].history) == 0202 assert len(response.history[1].history) == 1203204205@pytest.mark.usefixtures("async_environment")196async def test_too_many_redirects(backend):206async def test_too_many_redirects():207 client = Client(dispatch=MockDispatch())208 with pytest.raises(TooManyRedirects):209 await client.get("https://example.org/multiple_redirects?count=21")210211212@pytest.mark.usefixtures("async_environment")202async def test_too_many_redirects_calling_next(backend):213async def test_too_many_redirects_calling_next():214 client = Client(dispatch=MockDispatch())215 url = "https://example.org/multiple_redirects?count=21"216 response = await client.get(url, allow_redirects=False)217 with pytest.raises(TooManyRedirects):218 while response.is_redirect:219 response = await response.next()220221222@pytest.mark.usefixtures("async_environment")211async def test_redirect_loop(backend):223async def test_redirect_loop():224 client = Client(dispatch=MockDispatch())225 with pytest.raises(RedirectLoop):226 await client.get("https://example.org/redirect_loop")227228229@pytest.mark.usefixtures("async_environment")217async def test_redirect_loop_calling_next(backend):230async def test_redirect_loop_calling_next():231 client = Client(dispatch=MockDispatch())232 url = "https://example.org/redirect_loop"233 response = await client.get(url, allow_redirects=False)234 with pytest.raises(RedirectLoop):235 while response.is_redirect:236 response = await response.next()237238239@pytest.mark.usefixtures("async_environment")226async def test_cross_domain_redirect(backend):240async def test_cross_domain_redirect():241 client = Client(dispatch=MockDispatch())242 url = "https://example.com/cross_domain"243 headers = {"Authorization": "abc"}244 response = await client.get(url, headers=headers)245 assert response.url == URL("https://example.org/cross_domain_target")246 assert "authorization" not in response.json()["headers"]247248249@pytest.mark.usefixtures("async_environment")235async def test_same_domain_redirect(backend):250async def test_same_domain_redirect():251 client = Client(dispatch=MockDispatch())252 url = "https://example.org/cross_domain"253 headers = {"Authorization": "abc"}254 response = await client.get(url, headers=headers)255 assert response.url == URL("https://example.org/cross_domain_target")256 assert response.json()["headers"]["authorization"] == "abc"257258259@pytest.mark.usefixtures("async_environment")244async def test_body_redirect(backend):260async def test_body_redirect():261 """262 A 308 redirect should preserve the request body.263 """264 client = Client(dispatch=MockDispatch())
4 unmodified lines
269 assert response.json()["body"] == "Example request body"270 assert "content-length" in response.json()["headers"]271272273@pytest.mark.usefixtures("async_environment")257async def test_no_body_redirect(backend):274async def test_no_body_redirect():275 """276 A 303 redirect should remove the request body.277 """278 client = Client(dispatch=MockDispatch())
4 unmodified lines
283 assert response.json()["body"] == ""284 assert "content-length" not in response.json()["headers"]285286287@pytest.mark.usefixtures("async_environment")270async def test_cannot_redirect_streaming_body(backend):288async def test_cannot_redirect_streaming_body():289 client = Client(dispatch=MockDispatch())290 url = "https://example.org/redirect_body"291292 async def streaming_body():
2 unmodified lines
295 with pytest.raises(RedirectBodyUnavailable):296 await client.post(url, data=streaming_body())297298299@pytest.mark.usefixtures("async_environment")281async def test_cross_subdomain_redirect(backend):300async def test_cross_subdomain_redirect():301 client = Client(dispatch=MockDispatch())302 url = "https://example.com/cross_subdomain"303 response = await client.get(url)304 assert response.url == URL("https://www.example.org/cross_subdomain")
37 unmodified lines
342 }343 return Response(status_code, headers=headers, request=request)344345346@pytest.mark.usefixtures("async_environment")327async def test_redirect_cookie_behavior(backend):347async def test_redirect_cookie_behavior():348 client = Client(dispatch=MockCookieDispatch())349350 # The client is not logged in.351 response = await client.get("https://example.com/")
22 unmodified lines
modified:tests/dispatch/test_connection_pools.py+26 added-14 removed
1import pytest23import httpx4from httpx.dispatch.connection_pool import ConnectionPool567@pytest.mark.usefixtures("async_environment")5async def test_keepalive_connections(server, backend):8async def test_keepalive_connections(server):9 """10 Connections should default to staying in a keep-alive state.11 """12 async with ConnectionPool() as http:
7 unmodified lines
20 assert len(http.active_connections) == 021 assert len(http.keepalive_connections) == 1222324@pytest.mark.usefixtures("async_environment")21async def test_keepalive_timeout(server, backend):25async def test_keepalive_timeout(server):26 """27 Keep-alive connections should timeout.28 """29 async with ConnectionPool() as http:
22 unmodified lines
52 assert len(http.active_connections) == 053 assert len(http.keepalive_connections) == 0545556@pytest.mark.usefixtures("async_environment")52async def test_differing_connection_keys(server, backend):57async def test_differing_connection_keys(server):58 """59 Connections to differing connection keys should result in multiple connections.60 """61 async with ConnectionPool() as http:
7 unmodified lines
69 assert len(http.active_connections) == 070 assert len(http.keepalive_connections) == 2717273@pytest.mark.usefixtures("async_environment")68async def test_soft_limit(server, backend):74async def test_soft_limit(server):75 """76 The soft_limit config should limit the maximum number of keep-alive connections.77 """78 pool_limits = httpx.PoolLimits(soft_limit=1)
9 unmodified lines
88 assert len(http.active_connections) == 089 assert len(http.keepalive_connections) == 1909192@pytest.mark.usefixtures("async_environment")86async def test_streaming_response_holds_connection(server, backend):93async def test_streaming_response_holds_connection(server):94 """95 A streaming request should hold the connection open until the response is read.96 """97 async with ConnectionPool() as http:
6 unmodified lines
104 assert len(http.active_connections) == 0105 assert len(http.keepalive_connections) == 1106107108@pytest.mark.usefixtures("async_environment")101async def test_multiple_concurrent_connections(server, backend):109async def test_multiple_concurrent_connections(server):110 """111 Multiple conncurrent requests should open multiple conncurrent connections.112 """113 async with ConnectionPool() as http:
13 unmodified lines
127 assert len(http.active_connections) == 0128 assert len(http.keepalive_connections) == 2129130131@pytest.mark.usefixtures("async_environment")123async def test_close_connections(server, backend):132async def test_close_connections(server):133 """134 Using a `Connection: close` header should close the connection.135 """136 headers = [(b"connection", b"close")]
3 unmodified lines
140 assert len(http.active_connections) == 0141 assert len(http.keepalive_connections) == 0142143144@pytest.mark.usefixtures("async_environment")135async def test_standard_response_close(server, backend):145async def test_standard_response_close(server):146 """147 A standard close should keep the connection open.148 """149 async with ConnectionPool() as http:
3 unmodified lines
153 assert len(http.active_connections) == 0154 assert len(http.keepalive_connections) == 1155156157@pytest.mark.usefixtures("async_environment")147async def test_premature_response_close(server, backend):158async def test_premature_response_close(server):159 """160 A premature close should close the connection.161 """162 async with ConnectionPool() as http:
2 unmodified lines
165 assert len(http.active_connections) == 0166 assert len(http.keepalive_connections) == 0167168158async def test_keepalive_connection_closed_by_server_is_reestablished(159 server, restart, backend160):169@pytest.mark.usefixtures("async_environment")170async def test_keepalive_connection_closed_by_server_is_reestablished(server, restart):171 """172 Upon keep-alive connection closed by remote a new connection173 should be reestablished.174 """
9 unmodified lines
184 assert len(http.active_connections) == 0185 assert len(http.keepalive_connections) == 1186187188@pytest.mark.usefixtures("async_environment")189async def test_keepalive_http2_connection_closed_by_server_is_reestablished(179 server, restart, backend190 server, restart191):192 """193 Upon keep-alive connection closed by remote a new connection194 should be reestablished.
10 unmodified lines
205 assert len(http.active_connections) == 0206 assert len(http.keepalive_connections) == 1207208209@pytest.mark.usefixtures("async_environment")198async def test_connection_closed_free_semaphore_on_acquire(server, restart, backend):210async def test_connection_closed_free_semaphore_on_acquire(server, restart):211 """212 Verify that max_connections semaphore is released213 properly on a disconnected connection.214 """
9 unmodified lines
modified:tests/dispatch/test_connections.py+10 added-5 removed
2 unmodified lines
3import httpx4from httpx.dispatch.connection import HTTPConnection567@pytest.mark.usefixtures("async_environment")7async def test_get(server, backend):8async def test_get(server):9 async with HTTPConnection(origin=server.url) as conn:10 response = await conn.request("GET", server.url)11 await response.read()12 assert response.status_code == 20013 assert response.content == b"Hello, world!"141516@pytest.mark.usefixtures("async_environment")15async def test_post(server, backend):17async def test_post(server):18 async with HTTPConnection(origin=server.url) as conn:19 response = await conn.request("GET", server.url, data=b"Hello, world!")20 assert response.status_code == 200212223@pytest.mark.usefixtures("async_environment")21async def test_premature_close(server, backend):24async def test_premature_close(server):25 with pytest.raises(httpx.ConnectionClosed):26 async with HTTPConnection(origin=server.url) as conn:27 response = await conn.request(28 "GET", server.url.copy_with(path="/premature_close")29 )30 await response.read()313233@pytest.mark.usefixtures("async_environment")30async def test_https_get_with_ssl_defaults(https_server, ca_cert_pem_file, backend):34async def test_https_get_with_ssl_defaults(https_server, ca_cert_pem_file):35 """36 An HTTPS request, with default SSL configuration set on the client.37 """38 async with HTTPConnection(origin=https_server.url, verify=ca_cert_pem_file) as conn:
2 unmodified lines
41 assert response.status_code == 20042 assert response.content == b"Hello, world!"434445@pytest.mark.usefixtures("async_environment")41async def test_https_get_with_sll_overrides(https_server, ca_cert_pem_file, backend):46async def test_https_get_with_sll_overrides(https_server, ca_cert_pem_file):47 """48 An HTTPS request, with SSL configuration set on the request.49 """50 async with HTTPConnection(origin=https_server.url) as conn:
4 unmodified lines
modified:tests/dispatch/test_http2.py+4 added-2 removed
100 unmodified lines
101 assert response_2.status_code == 200102 assert json.loads(response_2.content) == {"method": "GET", "path": "/2", "body": ""}103104105@pytest.mark.asyncio105async def test_http2_settings_in_handshake(backend):106async def test_http2_settings_in_handshake():107 backend = MockHTTP2Backend(app=app)108109 async with Client(backend=backend, http2=True) as client:110 await client.get("http://example.org")
26 unmodified lines
137 assert isinstance(changed_setting, h2.settings.ChangedSetting)138 assert changed_setting.new_value == expected_settings[setting_code]139140141@pytest.mark.usefixtures("async_environment")140async def test_http2_live_request(backend):142async def test_http2_live_request():143 async with Client(http2=True) as client:144 try:145 resp = await client.get("https://nghttp2.org/httpbin/anything")146 except TimeoutException:
5 unmodified lines
modified:tests/dispatch/test_proxy_http.py+8 added-4 removed
3 unmodified lines
45from .utils import MockRawSocketBackend678@pytest.mark.asyncio8async def test_proxy_tunnel_success(backend):9async def test_proxy_tunnel_success():10 raw_io = MockRawSocketBackend(11 data_to_send=(12 [13 b"HTTP/1.1 200 OK\r\n"
27 unmodified lines
41 )42 assert recv[2].startswith(b"GET / HTTP/1.1\r\nhost: example.com\r\n")434445@pytest.mark.asyncio46@pytest.mark.parametrize("status_code", [300, 304, 308, 401, 500])45async def test_proxy_tunnel_non_2xx_response(backend, status_code):47async def test_proxy_tunnel_non_2xx_response(status_code):48 raw_io = MockRawSocketBackend(49 data_to_send=(50 [51 b"HTTP/1.1 %d Not Good\r\n" % status_code,
27 unmodified lines
79 b"CONNECT example.com:80 HTTP/1.1\r\nhost: 127.0.0.1:8000\r\n"80 )818283@pytest.mark.asyncio81async def test_proxy_tunnel_start_tls(backend):84async def test_proxy_tunnel_start_tls():85 raw_io = MockRawSocketBackend(86 data_to_send=(87 [88 # Tunnel Response
54 unmodified lines
143 assert recv[3].startswith(b"GET / HTTP/1.1\r\nhost: example.com\r\n")144 assert recv[4].startswith(b"GET /target HTTP/1.1\r\nhost: example.com\r\n")145146147@pytest.mark.asyncio148@pytest.mark.parametrize("proxy_mode", ["FORWARD_ONLY", "DEFAULT"])145async def test_proxy_forwarding(backend, proxy_mode):149async def test_proxy_forwarding(proxy_mode):150 raw_io = MockRawSocketBackend(151 data_to_send=(152 [153 b"HTTP/1.1 200 OK\r\n"
53 unmodified lines
modified:tests/conftest.py+27 added-20 removed
30 unmodified lines
31 "SSLKEYLOGFILE",32}333435@pytest.fixture(36 params=[37 pytest.param("asyncio", marks=pytest.mark.asyncio),38 pytest.param("trio", marks=pytest.mark.trio),39 ]40)41def async_environment(request: typing.Any) -> str:42 """43 Mark a test function to be run on both asyncio and trio.4445 Equivalent to having a pair of tests, each respectively marked with46 '@pytest.mark.asyncio' and '@pytest.mark.trio'.4748 Intended usage:4950 ```51 @pytest.mark.usefixtures("async_environment")52 async def my_async_test():53 ...54 ```55 """56 return request.param575859@pytest.fixture(scope="function", autouse=True)60def clean_environ() -> typing.Dict[str, typing.Any]:61 """Keeps os.environ clean for every test without having to mock os.environ"""62 original_environ = os.environ.copy()
9 unmodified lines
72 os.environ.clear()73 os.environ.update(original_environ)747552@pytest.fixture(53 params=[54 # pytest uses the marks to set up the specified async environment and run55 # 'async def' test functions. The "auto" backend should then auto-detect56 # the environment it's running in.57 # Passing the backend explicitly, e.g. `backend="asyncio"`,58 # is tested separately.59 pytest.param("auto", marks=pytest.mark.asyncio),60 pytest.param("auto", marks=pytest.mark.trio),61 ]62)63def backend(request):64 return request.param656676async def app(scope, receive, send):77 assert scope["type"] == "http"78 if scope["path"].startswith("/slow_response"):79 await slow_response(scope, receive, send)
197 unmodified lines
277 await self.startup()278279280@pytest.fixture272def restart(backend):281def restart():282 """Restart the running server from an async test function.283284 This fixture deals with possible differences between the environment of the285 test function and that of the server.286 """287 asyncio_backend = AsyncioBackend()279 backend_implementation = lookup_backend(backend)288289 async def restart(server):282 await backend_implementation.run_in_threadpool(283 asyncio_backend.run, server.restart284 )290 backend = lookup_backend()291 await backend.run_in_threadpool(asyncio_backend.run, server.restart)292293 return restart294295
57 unmodified lines
modified:tests/test_concurrency.py+9 added-6 removed
27 unmodified lines
28 assert ended29 return response303132@pytest.mark.usefixtures("async_environment")32async def test_start_tls_on_tcp_socket_stream(https_server, backend):33 backend = lookup_backend(backend)33async def test_start_tls_on_tcp_socket_stream(https_server):34 backend = lookup_backend()35 ctx = SSLConfig().load_ssl_context_no_verify()36 timeout = Timeout(5)3738 stream = await backend.open_tcp_stream(
16 unmodified lines
55 finally:56 await stream.close()575859@pytest.mark.usefixtures("async_environment")58async def test_start_tls_on_uds_socket_stream(https_uds_server, backend):59 backend = lookup_backend(backend)60async def test_start_tls_on_uds_socket_stream(https_uds_server):61 backend = lookup_backend()62 ctx = SSLConfig().load_ssl_context_no_verify()63 timeout = Timeout(5)6465 stream = await backend.open_uds_stream(
16 unmodified lines
82 finally:83 await stream.close()848586@pytest.mark.usefixtures("async_environment")84async def test_concurrent_read(server, backend):87async def test_concurrent_read(server):88 """89 Regression test for: https://github.com/encode/httpx/issues/52790 """88 backend = lookup_backend(backend)91 backend = lookup_backend()92 stream = await backend.open_tcp_stream(93 server.url.host, server.url.port, ssl_context=None, timeout=Timeout(5)94 )95 timeout = Timeout(5)
27 unmodified lines
modified:tests/test_timeouts.py+8 added-4 removed
1 unmodified line
23import httpx456@pytest.mark.usefixtures("async_environment")6async def test_read_timeout(server, backend):7async def test_read_timeout(server):8 timeout = httpx.Timeout(read_timeout=1e-6)910 async with httpx.Client(timeout=timeout) as client:11 with pytest.raises(httpx.ReadTimeout):12 await client.get(server.url.copy_with(path="/slow_response"))131415@pytest.mark.usefixtures("async_environment")14async def test_write_timeout(server, backend):16async def test_write_timeout(server):17 timeout = httpx.Timeout(write_timeout=1e-6)1819 async with httpx.Client(timeout=timeout) as client:20 with pytest.raises(httpx.WriteTimeout):21 data = b"*" * 1024 * 1024 * 10022 await client.put(server.url.copy_with(path="/slow_response"), data=data)232425@pytest.mark.usefixtures("async_environment")23async def test_connect_timeout(server, backend):26async def test_connect_timeout(server):27 timeout = httpx.Timeout(connect_timeout=1e-6)2829 async with httpx.Client(timeout=timeout) as client:30 with pytest.raises(httpx.ConnectTimeout):31 # See https://stackoverflow.com/questions/100841/32 await client.get("http://10.255.255.1/")333435@pytest.mark.usefixtures("async_environment")32async def test_pool_timeout(server, backend):36async def test_pool_timeout(server):37 pool_limits = httpx.PoolLimits(hard_limit=1)38 timeout = httpx.Timeout(pool_timeout=1e-4)3940 async with httpx.Client(pool_limits=pool_limits, timeout=timeout) as client:
3 unmodified lines