Skip to content

Commit e27d1b8

Browse files
replace pytest-asyncio and pytest-trio with anyio (#2512)
* replace pytest-asyncio with anyio * remove pytest-trio also * Update setup.cfg * use anyio.Lock in test_auth Co-authored-by: Tom Christie <tom@tomchristie.com>
1 parent e4438a3 commit e27d1b8

15 files changed

+120
-146
lines changed

requirements.txt

-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ isort==5.11.4
3131
mypy==0.982
3232
types-certifi==2021.10.8.2
3333
pytest==7.2.0
34-
pytest-asyncio==0.20.3
35-
pytest-trio==0.7.0
3634
trio==0.21.0
3735
trio-typing==0.7.0
3836
trustme==0.9.0

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ combine_as_imports = True
1818
addopts = -rxXs
1919
filterwarnings =
2020
error
21-
asyncio_mode = strict
21+
ignore: You seem to already have a custom sys.excepthook handler installed. I'll skip installing Trio's custom handler, but this means MultiErrors will not show full tracebacks.:RuntimeWarning
2222
markers =
2323
copied_from(source, changes=None): mark test as copied from somewhere else, along with a description of changes made to accodomate e.g. our test setup
2424
network: marks tests which require network connection. Used in 3rd-party build environments that have network disabled.

tests/client/test_async_client.py

+24-24
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import httpx
77

88

9-
@pytest.mark.usefixtures("async_environment")
9+
@pytest.mark.anyio
1010
async def test_get(server):
1111
url = server.url
1212
async with httpx.AsyncClient(http2=True) as client:
@@ -27,14 +27,14 @@ async def test_get(server):
2727
pytest.param("http://", id="no-host"),
2828
],
2929
)
30-
@pytest.mark.usefixtures("async_environment")
30+
@pytest.mark.anyio
3131
async def test_get_invalid_url(server, url):
3232
async with httpx.AsyncClient() as client:
3333
with pytest.raises((httpx.UnsupportedProtocol, httpx.LocalProtocolError)):
3434
await client.get(url)
3535

3636

37-
@pytest.mark.usefixtures("async_environment")
37+
@pytest.mark.anyio
3838
async def test_build_request(server):
3939
url = server.url.copy_with(path="/echo_headers")
4040
headers = {"Custom-header": "value"}
@@ -49,23 +49,23 @@ async def test_build_request(server):
4949
assert response.json()["Custom-header"] == "value"
5050

5151

52-
@pytest.mark.usefixtures("async_environment")
52+
@pytest.mark.anyio
5353
async def test_post(server):
5454
url = server.url
5555
async with httpx.AsyncClient() as client:
5656
response = await client.post(url, content=b"Hello, world!")
5757
assert response.status_code == 200
5858

5959

60-
@pytest.mark.usefixtures("async_environment")
60+
@pytest.mark.anyio
6161
async def test_post_json(server):
6262
url = server.url
6363
async with httpx.AsyncClient() as client:
6464
response = await client.post(url, json={"text": "Hello, world!"})
6565
assert response.status_code == 200
6666

6767

68-
@pytest.mark.usefixtures("async_environment")
68+
@pytest.mark.anyio
6969
async def test_stream_response(server):
7070
async with httpx.AsyncClient() as client:
7171
async with client.stream("GET", server.url) as response:
@@ -76,7 +76,7 @@ async def test_stream_response(server):
7676
assert response.content == b"Hello, world!"
7777

7878

79-
@pytest.mark.usefixtures("async_environment")
79+
@pytest.mark.anyio
8080
async def test_access_content_stream_response(server):
8181
async with httpx.AsyncClient() as client:
8282
async with client.stream("GET", server.url) as response:
@@ -87,7 +87,7 @@ async def test_access_content_stream_response(server):
8787
response.content
8888

8989

90-
@pytest.mark.usefixtures("async_environment")
90+
@pytest.mark.anyio
9191
async def test_stream_request(server):
9292
async def hello_world() -> typing.AsyncIterator[bytes]:
9393
yield b"Hello, "
@@ -98,7 +98,7 @@ async def hello_world() -> typing.AsyncIterator[bytes]:
9898
assert response.status_code == 200
9999

100100

101-
@pytest.mark.usefixtures("async_environment")
101+
@pytest.mark.anyio
102102
async def test_cannot_stream_sync_request(server):
103103
def hello_world() -> typing.Iterator[bytes]: # pragma: no cover
104104
yield b"Hello, "
@@ -109,7 +109,7 @@ def hello_world() -> typing.Iterator[bytes]: # pragma: no cover
109109
await client.post(server.url, content=hello_world())
110110

111111

112-
@pytest.mark.usefixtures("async_environment")
112+
@pytest.mark.anyio
113113
async def test_raise_for_status(server):
114114
async with httpx.AsyncClient() as client:
115115
for status_code in (200, 400, 404, 500, 505):
@@ -125,45 +125,45 @@ async def test_raise_for_status(server):
125125
assert response.raise_for_status() is None # type: ignore
126126

127127

128-
@pytest.mark.usefixtures("async_environment")
128+
@pytest.mark.anyio
129129
async def test_options(server):
130130
async with httpx.AsyncClient() as client:
131131
response = await client.options(server.url)
132132
assert response.status_code == 200
133133
assert response.text == "Hello, world!"
134134

135135

136-
@pytest.mark.usefixtures("async_environment")
136+
@pytest.mark.anyio
137137
async def test_head(server):
138138
async with httpx.AsyncClient() as client:
139139
response = await client.head(server.url)
140140
assert response.status_code == 200
141141
assert response.text == ""
142142

143143

144-
@pytest.mark.usefixtures("async_environment")
144+
@pytest.mark.anyio
145145
async def test_put(server):
146146
async with httpx.AsyncClient() as client:
147147
response = await client.put(server.url, content=b"Hello, world!")
148148
assert response.status_code == 200
149149

150150

151-
@pytest.mark.usefixtures("async_environment")
151+
@pytest.mark.anyio
152152
async def test_patch(server):
153153
async with httpx.AsyncClient() as client:
154154
response = await client.patch(server.url, content=b"Hello, world!")
155155
assert response.status_code == 200
156156

157157

158-
@pytest.mark.usefixtures("async_environment")
158+
@pytest.mark.anyio
159159
async def test_delete(server):
160160
async with httpx.AsyncClient() as client:
161161
response = await client.delete(server.url)
162162
assert response.status_code == 200
163163
assert response.text == "Hello, world!"
164164

165165

166-
@pytest.mark.usefixtures("async_environment")
166+
@pytest.mark.anyio
167167
async def test_100_continue(server):
168168
headers = {"Expect": "100-continue"}
169169
content = b"Echo request body"
@@ -177,7 +177,7 @@ async def test_100_continue(server):
177177
assert response.content == content
178178

179179

180-
@pytest.mark.usefixtures("async_environment")
180+
@pytest.mark.anyio
181181
async def test_context_managed_transport():
182182
class Transport(httpx.AsyncBaseTransport):
183183
def __init__(self) -> None:
@@ -209,7 +209,7 @@ async def __aexit__(self, *args):
209209
]
210210

211211

212-
@pytest.mark.usefixtures("async_environment")
212+
@pytest.mark.anyio
213213
async def test_context_managed_transport_and_mount():
214214
class Transport(httpx.AsyncBaseTransport):
215215
def __init__(self, name: str):
@@ -254,7 +254,7 @@ def hello_world(request):
254254
return httpx.Response(200, text="Hello, world!")
255255

256256

257-
@pytest.mark.usefixtures("async_environment")
257+
@pytest.mark.anyio
258258
async def test_client_closed_state_using_implicit_open():
259259
client = httpx.AsyncClient(transport=httpx.MockTransport(hello_world))
260260

@@ -275,7 +275,7 @@ async def test_client_closed_state_using_implicit_open():
275275
pass # pragma: no cover
276276

277277

278-
@pytest.mark.usefixtures("async_environment")
278+
@pytest.mark.anyio
279279
async def test_client_closed_state_using_with_block():
280280
async with httpx.AsyncClient(transport=httpx.MockTransport(hello_world)) as client:
281281
assert not client.is_closed
@@ -296,7 +296,7 @@ def mounted(request: httpx.Request) -> httpx.Response:
296296
return httpx.Response(200, json=data)
297297

298298

299-
@pytest.mark.usefixtures("async_environment")
299+
@pytest.mark.anyio
300300
async def test_mounted_transport():
301301
transport = httpx.MockTransport(unmounted)
302302
mounts = {"custom://": httpx.MockTransport(mounted)}
@@ -311,7 +311,7 @@ async def test_mounted_transport():
311311
assert response.json() == {"app": "mounted"}
312312

313313

314-
@pytest.mark.usefixtures("async_environment")
314+
@pytest.mark.anyio
315315
async def test_async_mock_transport():
316316
async def hello_world(request):
317317
return httpx.Response(200, text="Hello, world!")
@@ -324,7 +324,7 @@ async def hello_world(request):
324324
assert response.text == "Hello, world!"
325325

326326

327-
@pytest.mark.usefixtures("async_environment")
327+
@pytest.mark.anyio
328328
async def test_cancellation_during_stream():
329329
"""
330330
If any BaseException is raised during streaming the response, then the
@@ -364,7 +364,7 @@ async def aclose(self) -> None:
364364
assert stream_was_closed
365365

366366

367-
@pytest.mark.usefixtures("async_environment")
367+
@pytest.mark.anyio
368368
async def test_server_extensions(server):
369369
url = server.url
370370
async with httpx.AsyncClient(http2=True) as client:

0 commit comments

Comments
 (0)