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
Provenance
- Commit
d0427be- Tree
716cd81- Author
Florimond Manca <florimond.manca@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
56c8eda
9 files changed+164 added−114 removed
modified:tests/client/test_async_client.py+32 added-39 removed
3 unmodified lines4 5 import httpx6 7 8+@pytest.mark.usefixtures("async_environment")8-async def test_get(server, backend):9+async 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 == 2003 unmodified lines17 assert repr(response) == "<Response [200 OK]>"18 assert response.elapsed > timedelta(seconds=0)19 20 21+@pytest.mark.usefixtures("async_environment")20-async def test_build_request(server, backend):22+async 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 lines32 33 assert response.json()["Custom-header"] == "value"34 35 34-@pytest.mark.asyncio35-async 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")37+async 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]>"47-48-49-async 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 == 20042 43 44+@pytest.mark.usefixtures("async_environment")56-async def test_post_json(server, backend):45+async 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 == 20050 51 52+@pytest.mark.usefixtures("async_environment")63-async def test_stream_response(server, backend):53+async 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 line59 assert body == b"Hello, world!"60 assert response.content == b"Hello, world!"61 62 63+@pytest.mark.usefixtures("async_environment")73-async def test_access_content_stream_response(server, backend):64+async 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 line70 with pytest.raises(httpx.ResponseNotRead):71 response.content72 73 74+@pytest.mark.usefixtures("async_environment")83-async def test_stream_request(server, backend):75+async def test_stream_request(server):76 async def hello_world():77 yield b"Hello, "78 yield b"world!"79 1 unmodified line81 response = await client.request("POST", server.url, data=hello_world())82 assert response.status_code == 20083 84 85+@pytest.mark.usefixtures("async_environment")93-async def test_raise_for_status(server, backend):86+async 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 lines97 else:98 assert response.raise_for_status() is None99 100 101+@pytest.mark.usefixtures("async_environment")108-async def test_options(server, backend):102+async 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!"107 108 109+@pytest.mark.usefixtures("async_environment")115-async def test_head(server, backend):110+async 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 == ""115 116 117+@pytest.mark.usefixtures("async_environment")122-async def test_put(server, backend):118+async 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 == 200122 123 124+@pytest.mark.usefixtures("async_environment")128-async def test_patch(server, backend):125+async 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 == 200129 130 131+@pytest.mark.usefixtures("async_environment")134-async def test_delete(server, backend):132+async 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!"137 138 139+@pytest.mark.usefixtures("async_environment")141-async def test_100_continue(server, backend):140+async def test_100_continue(server):141 headers = {"Expect": "100-continue"}142 data = b"Echo request body"143 144 async with httpx.Client() as client:4 unmodified lines149 assert response.status_code == 200150 assert response.content == data151 152 153+@pytest.mark.usefixtures("async_environment")154-async def test_uds(uds_server, backend):154+async 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 lines161 assert response.text == "Hello, world!"162 assert response.encoding == "iso-8859-1"163 164 165-@pytest.mark.parametrize(166- "backend",167- [168- pytest.param("asyncio", marks=pytest.mark.asyncio),169- pytest.param("trio", marks=pytest.mark.trio),170- ],171-)172-async def test_explicit_backend(server, backend):173- async with httpx.Client(backend=backend) as client:165+async 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 lines102 103 return Response(codes.OK, content=b"Hello, world!", request=request)104 105 106+@pytest.mark.usefixtures("async_environment")106-async def test_no_redirect(backend):107+async 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()114 115 116+@pytest.mark.usefixtures("async_environment")115-async def test_redirect_301(backend):117+async 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) == 1123 124 125+@pytest.mark.usefixtures("async_environment")123-async def test_redirect_302(backend):126+async 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) == 1132 133 134+@pytest.mark.usefixtures("async_environment")131-async def test_redirect_303(backend):135+async 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) == 1141 142 143+@pytest.mark.usefixtures("async_environment")139-async def test_disallow_redirects(backend):144+async 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 lines157 assert response.is_redirect is False158 assert len(response.history) == 1159 160 161+@pytest.mark.usefixtures("async_environment")156-async def test_relative_redirect(backend):162+async 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) == 1168 169 170+@pytest.mark.usefixtures("async_environment")164-async def test_no_scheme_redirect(backend):171+async 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) == 1177 178 179+@pytest.mark.usefixtures("async_environment")172-async def test_fragment_redirect(backend):180+async 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) == 1186 187 188+@pytest.mark.usefixtures("async_environment")180-async def test_multiple_redirects(backend):189+async 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 lines201 assert len(response.history[0].history) == 0202 assert len(response.history[1].history) == 1203 204 205+@pytest.mark.usefixtures("async_environment")196-async def test_too_many_redirects(backend):206+async 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")210 211 212+@pytest.mark.usefixtures("async_environment")202-async def test_too_many_redirects_calling_next(backend):213+async 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()220 221 222+@pytest.mark.usefixtures("async_environment")211-async def test_redirect_loop(backend):223+async def test_redirect_loop():224 client = Client(dispatch=MockDispatch())225 with pytest.raises(RedirectLoop):226 await client.get("https://example.org/redirect_loop")227 228 229+@pytest.mark.usefixtures("async_environment")217-async def test_redirect_loop_calling_next(backend):230+async 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()237 238 239+@pytest.mark.usefixtures("async_environment")226-async def test_cross_domain_redirect(backend):240+async 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"]247 248 249+@pytest.mark.usefixtures("async_environment")235-async def test_same_domain_redirect(backend):250+async 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"257 258 259+@pytest.mark.usefixtures("async_environment")244-async def test_body_redirect(backend):260+async def test_body_redirect():261 """262 A 308 redirect should preserve the request body.263 """264 client = Client(dispatch=MockDispatch())4 unmodified lines269 assert response.json()["body"] == "Example request body"270 assert "content-length" in response.json()["headers"]271 272 273+@pytest.mark.usefixtures("async_environment")257-async def test_no_body_redirect(backend):274+async def test_no_body_redirect():275 """276 A 303 redirect should remove the request body.277 """278 client = Client(dispatch=MockDispatch())4 unmodified lines283 assert response.json()["body"] == ""284 assert "content-length" not in response.json()["headers"]285 286 287+@pytest.mark.usefixtures("async_environment")270-async def test_cannot_redirect_streaming_body(backend):288+async def test_cannot_redirect_streaming_body():289 client = Client(dispatch=MockDispatch())290 url = "https://example.org/redirect_body"291 292 async def streaming_body():2 unmodified lines295 with pytest.raises(RedirectBodyUnavailable):296 await client.post(url, data=streaming_body())297 298 299+@pytest.mark.usefixtures("async_environment")281-async def test_cross_subdomain_redirect(backend):300+async 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 lines342 }343 return Response(status_code, headers=headers, request=request)344 345 346+@pytest.mark.usefixtures("async_environment")327-async def test_redirect_cookie_behavior(backend):347+async def test_redirect_cookie_behavior():348 client = Client(dispatch=MockCookieDispatch())349 350 # The client is not logged in.351 response = await client.get("https://example.com/")22 unmodified linesmodified:tests/dispatch/test_connection_pools.py+26 added-14 removed
1+import pytest2+3 import httpx4 from httpx.dispatch.connection_pool import ConnectionPool5 6 7+@pytest.mark.usefixtures("async_environment")5-async def test_keepalive_connections(server, backend):8+async 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 lines20 assert len(http.active_connections) == 021 assert len(http.keepalive_connections) == 122 23 24+@pytest.mark.usefixtures("async_environment")21-async def test_keepalive_timeout(server, backend):25+async def test_keepalive_timeout(server):26 """27 Keep-alive connections should timeout.28 """29 async with ConnectionPool() as http:22 unmodified lines52 assert len(http.active_connections) == 053 assert len(http.keepalive_connections) == 054 55 56+@pytest.mark.usefixtures("async_environment")52-async def test_differing_connection_keys(server, backend):57+async 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 lines69 assert len(http.active_connections) == 070 assert len(http.keepalive_connections) == 271 72 73+@pytest.mark.usefixtures("async_environment")68-async def test_soft_limit(server, backend):74+async 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 lines88 assert len(http.active_connections) == 089 assert len(http.keepalive_connections) == 190 91 92+@pytest.mark.usefixtures("async_environment")86-async def test_streaming_response_holds_connection(server, backend):93+async 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 lines104 assert len(http.active_connections) == 0105 assert len(http.keepalive_connections) == 1106 107 108+@pytest.mark.usefixtures("async_environment")101-async def test_multiple_concurrent_connections(server, backend):109+async 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 lines127 assert len(http.active_connections) == 0128 assert len(http.keepalive_connections) == 2129 130 131+@pytest.mark.usefixtures("async_environment")123-async def test_close_connections(server, backend):132+async 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 lines140 assert len(http.active_connections) == 0141 assert len(http.keepalive_connections) == 0142 143 144+@pytest.mark.usefixtures("async_environment")135-async def test_standard_response_close(server, backend):145+async 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 lines153 assert len(http.active_connections) == 0154 assert len(http.keepalive_connections) == 1155 156 157+@pytest.mark.usefixtures("async_environment")147-async def test_premature_response_close(server, backend):158+async def test_premature_response_close(server):159 """160 A premature close should close the connection.161 """162 async with ConnectionPool() as http:2 unmodified lines165 assert len(http.active_connections) == 0166 assert len(http.keepalive_connections) == 0167 168 158-async def test_keepalive_connection_closed_by_server_is_reestablished(159- server, restart, backend160-):169+@pytest.mark.usefixtures("async_environment")170+async 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 lines184 assert len(http.active_connections) == 0185 assert len(http.keepalive_connections) == 1186 187 188+@pytest.mark.usefixtures("async_environment")189 async 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 lines205 assert len(http.active_connections) == 0206 assert len(http.keepalive_connections) == 1207 208 209+@pytest.mark.usefixtures("async_environment")198-async def test_connection_closed_free_semaphore_on_acquire(server, restart, backend):210+async 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 linesmodified:tests/dispatch/test_connections.py+10 added-5 removed
2 unmodified lines3 import httpx4 from httpx.dispatch.connection import HTTPConnection5 6 7+@pytest.mark.usefixtures("async_environment")7-async def test_get(server, backend):8+async 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!"14 15 16+@pytest.mark.usefixtures("async_environment")15-async def test_post(server, backend):17+async 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 == 20021 22 23+@pytest.mark.usefixtures("async_environment")21-async def test_premature_close(server, backend):24+async 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()31 32 33+@pytest.mark.usefixtures("async_environment")30-async def test_https_get_with_ssl_defaults(https_server, ca_cert_pem_file, backend):34+async 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 lines41 assert response.status_code == 20042 assert response.content == b"Hello, world!"43 44 45+@pytest.mark.usefixtures("async_environment")41-async def test_https_get_with_sll_overrides(https_server, ca_cert_pem_file, backend):46+async 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 linesmodified:tests/dispatch/test_http2.py+4 added-2 removed
100 unmodified lines101 assert response_2.status_code == 200102 assert json.loads(response_2.content) == {"method": "GET", "path": "/2", "body": ""}103 104 105+@pytest.mark.asyncio105-async def test_http2_settings_in_handshake(backend):106+async def test_http2_settings_in_handshake():107 backend = MockHTTP2Backend(app=app)108 109 async with Client(backend=backend, http2=True) as client:110 await client.get("http://example.org")26 unmodified lines137 assert isinstance(changed_setting, h2.settings.ChangedSetting)138 assert changed_setting.new_value == expected_settings[setting_code]139 140 141+@pytest.mark.usefixtures("async_environment")140-async def test_http2_live_request(backend):142+async 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 linesmodified:tests/dispatch/test_proxy_http.py+8 added-4 removed
3 unmodified lines4 5 from .utils import MockRawSocketBackend6 7 8+@pytest.mark.asyncio8-async def test_proxy_tunnel_success(backend):9+async 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 lines41 )42 assert recv[2].startswith(b"GET / HTTP/1.1\r\nhost: example.com\r\n")43 44 45+@pytest.mark.asyncio46 @pytest.mark.parametrize("status_code", [300, 304, 308, 401, 500])45-async def test_proxy_tunnel_non_2xx_response(backend, status_code):47+async 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 lines79 b"CONNECT example.com:80 HTTP/1.1\r\nhost: 127.0.0.1:8000\r\n"80 )81 82 83+@pytest.mark.asyncio81-async def test_proxy_tunnel_start_tls(backend):84+async def test_proxy_tunnel_start_tls():85 raw_io = MockRawSocketBackend(86 data_to_send=(87 [88 # Tunnel Response54 unmodified lines143 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")145 146 147+@pytest.mark.asyncio148 @pytest.mark.parametrize("proxy_mode", ["FORWARD_ONLY", "DEFAULT"])145-async def test_proxy_forwarding(backend, proxy_mode):149+async 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 linesmodified:tests/conftest.py+27 added-20 removed
30 unmodified lines31 "SSLKEYLOGFILE",32 }33 34 35+@pytest.fixture(36+ params=[37+ pytest.param("asyncio", marks=pytest.mark.asyncio),38+ pytest.param("trio", marks=pytest.mark.trio),39+ ]40+)41+def async_environment(request: typing.Any) -> str:42+ """43+ Mark a test function to be run on both asyncio and trio.44+45+ Equivalent to having a pair of tests, each respectively marked with46+ '@pytest.mark.asyncio' and '@pytest.mark.trio'.47+48+ Intended usage:49+50+ ```51+ @pytest.mark.usefixtures("async_environment")52+ async def my_async_test():53+ ...54+ ```55+ """56+ return request.param57+58+59 @pytest.fixture(scope="function", autouse=True)60 def 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 lines72 os.environ.clear()73 os.environ.update(original_environ)74 75 52-@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-)63-def backend(request):64- return request.param65-66-76 async 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 lines277 await self.startup()278 279 280 @pytest.fixture272-def restart(backend):281+def restart():282 """Restart the running server from an async test function.283 284 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)288 289 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)292 293 return restart294 295 57 unmodified linesmodified:tests/test_concurrency.py+9 added-6 removed
27 unmodified lines28 assert ended29 return response30 31 32+@pytest.mark.usefixtures("async_environment")32-async def test_start_tls_on_tcp_socket_stream(https_server, backend):33- backend = lookup_backend(backend)33+async 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)37 38 stream = await backend.open_tcp_stream(16 unmodified lines55 finally:56 await stream.close()57 58 59+@pytest.mark.usefixtures("async_environment")58-async def test_start_tls_on_uds_socket_stream(https_uds_server, backend):59- backend = lookup_backend(backend)60+async 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)64 65 stream = await backend.open_uds_stream(16 unmodified lines82 finally:83 await stream.close()84 85 86+@pytest.mark.usefixtures("async_environment")84-async def test_concurrent_read(server, backend):87+async 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 linesmodified:tests/test_timeouts.py+8 added-4 removed
1 unmodified line2 3 import httpx4 5 6+@pytest.mark.usefixtures("async_environment")6-async def test_read_timeout(server, backend):7+async def test_read_timeout(server):8 timeout = httpx.Timeout(read_timeout=1e-6)9 10 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"))13 14 15+@pytest.mark.usefixtures("async_environment")14-async def test_write_timeout(server, backend):16+async def test_write_timeout(server):17 timeout = httpx.Timeout(write_timeout=1e-6)18 19 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)23 24 25+@pytest.mark.usefixtures("async_environment")23-async def test_connect_timeout(server, backend):26+async def test_connect_timeout(server):27 timeout = httpx.Timeout(connect_timeout=1e-6)28 29 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/")33 34 35+@pytest.mark.usefixtures("async_environment")32-async def test_pool_timeout(server, backend):36+async def test_pool_timeout(server):37 pool_limits = httpx.PoolLimits(hard_limit=1)38 timeout = httpx.Timeout(pool_timeout=1e-4)39 40 async with httpx.Client(pool_limits=pool_limits, timeout=timeout) as client:3 unmodified lines