Skip to content

Commit af785e2

Browse files
webknjazbdraco
andcommitted
🧪💅 Integrate pytest-xdist into test runner
Co-authored-by: J. Nick Koston <[email protected]>
1 parent 34276a0 commit af785e2

File tree

9 files changed

+191
-17
lines changed

9 files changed

+191
-17
lines changed

.github/workflows/ci-cd.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,15 @@ jobs:
220220
COLOR: yes
221221
AIOHTTP_NO_EXTENSIONS: ${{ matrix.no-extensions }}
222222
run: >- # `exit 1` makes sure that the job remains red with flaky runs
223-
pytest --no-cov -vvvvv --lf && exit 1
223+
pytest --no-cov --numprocesses=0 -vvvvv --lf && exit 1
224224
shell: bash
225225
- name: Run dev_mode tests
226226
env:
227227
COLOR: yes
228228
AIOHTTP_NO_EXTENSIONS: ${{ matrix.no-extensions }}
229229
PIP_USER: 1
230-
run: python -X dev -m pytest -m dev_mode --cov-append
230+
PYTHONDEVMODE: 1
231+
run: pytest -m dev_mode --cov-append --numprocesses=0
231232
shell: bash
232233
- name: Turn coverage into xml
233234
env:

requirements/constraints.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ alabaster==0.7.13
1818
# via sphinx
1919
annotated-types==0.7.0
2020
# via pydantic
21+
apipkg==1.5
22+
# via execnet
2123
async-timeout==4.0.3 ; python_version < "3.11"
2224
# via
2325
# -r requirements/runtime-deps.in
@@ -69,6 +71,8 @@ filelock==3.16.1
6971
# via
7072
# pytest-codspeed
7173
# virtualenv
74+
execnet==2.1.1
75+
# via pytest-xdist
7276
freezegun==1.5.1
7377
# via
7478
# -r requirements/lint.in
@@ -145,6 +149,8 @@ proxy-py==2.4.9
145149
# via
146150
# -r requirements/lint.in
147151
# -r requirements/test.in
152+
py==1.11.0
153+
# via pytest
148154
pycares==4.4.0
149155
# via aiodns
150156
pycparser==2.22
@@ -174,12 +180,25 @@ pytest==8.1.1
174180
# pytest-codspeed
175181
# pytest-cov
176182
# pytest-mock
183+
# pytest-xdist
177184
pytest-codspeed==3.0.0
178185
# via
179186
# -r requirements/lint.in
180187
# -r requirements/test.in
181188
pytest-cov==5.0.0
182189
# via -r requirements/test.in
190+
pytest-mock==3.14.0
191+
# via -r requirements/test.in
192+
pytest-xdist==3.6.1
193+
# via -r requirements/test.txt
194+
python-dateutil==2.8.2
195+
# via freezegun
196+
python-on-whales==0.71.0
197+
# via
198+
# -r requirements/lint.in
199+
# -r requirements/test.in
200+
pytest-cov==5.0.0
201+
# via -r requirements/test.in
183202
pytest-mock==3.14.0
184203
# via
185204
# -r requirements/lint.in

requirements/test.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
coverage
44
freezegun
55
mypy; implementation_name == "cpython"
6-
proxy.py >= 2.4.4rc4
6+
proxy.py >= 2.4.4rc5
77
pytest
88
pytest-cov
99
pytest-mock
10+
pytest-xdist
1011
pytest_codspeed
1112
python-on-whales
1213
setuptools-git

requirements/test.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ cryptography==43.0.3
3737
# via trustme
3838
exceptiongroup==1.2.2
3939
# via pytest
40+
execnet==2.1.1
41+
# via pytest-xdist
4042
filelock==3.16.1
4143
# via pytest-codspeed
4244
freezegun==1.5.1
@@ -78,6 +80,8 @@ propcache==0.2.0
7880
# yarl
7981
proxy-py==2.4.9
8082
# via -r requirements/test.in
83+
py==1.11.0
84+
# via pytest
8185
pycares==4.4.0
8286
# via aiodns
8387
pycparser==2.22
@@ -95,11 +99,15 @@ pytest==8.1.1
9599
# pytest-cov
96100
# pytest-mock
97101
pytest-codspeed==3.0.0
98-
# via -r requirements/test.in
102+
# via
103+
# -r requirements/test.in
104+
# pytest-xdist
99105
pytest-cov==5.0.0
100106
# via -r requirements/test.in
101107
pytest-mock==3.14.0
102108
# via -r requirements/test.in
109+
pytest-xdist==3.6.1
110+
# via -r requirements/test.in
103111
python-dateutil==2.9.0.post0
104112
# via freezegun
105113
python-on-whales==0.73.0

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ exclude_lines =
124124

125125
[tool:pytest]
126126
addopts =
127+
# `pytest-xdist`:
128+
--numprocesses=auto
129+
127130
# show 10 slowest invocations:
128131
--durations=10
129132

tests/test_client_request.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,8 @@ async def test_urlencoded_formdata_charset(
736736
data=aiohttp.FormData({"hey": "you"}, charset="koi8-r"),
737737
loop=loop,
738738
)
739-
await req.send(conn)
739+
async with await req.send(conn):
740+
await asyncio.sleep(0)
740741
assert "application/x-www-form-urlencoded; charset=koi8-r" == req.headers.get(
741742
"CONTENT-TYPE"
742743
)
@@ -755,7 +756,8 @@ async def test_formdata_boundary_from_headers(
755756
headers={"Content-Type": f"multipart/form-data; boundary={boundary}"},
756757
loop=loop,
757758
)
758-
await req.send(conn)
759+
async with await req.send(conn):
760+
await asyncio.sleep(0)
759761
assert req.body._boundary == boundary.encode()
760762

761763

@@ -1088,13 +1090,13 @@ async def throw_exc() -> None:
10881090

10891091
t = loop.create_task(throw_exc())
10901092

1091-
await req.send(conn)
1092-
assert req._writer is not None
1093-
await req._writer
1094-
await t
1095-
# assert conn.close.called
1096-
assert conn.protocol is not None
1097-
assert conn.protocol.set_exception.called
1093+
async with await req.send(conn):
1094+
assert req._writer is not None
1095+
await req._writer
1096+
await t
1097+
# assert conn.close.called
1098+
assert conn.protocol is not None
1099+
assert conn.protocol.set_exception.called
10981100
await req.close()
10991101

11001102

@@ -1118,9 +1120,9 @@ async def throw_exc() -> None:
11181120

11191121
t = loop.create_task(throw_exc())
11201122

1121-
await req.send(conn)
1122-
assert req._writer is not None
1123-
await req._writer
1123+
async with await req.send(conn):
1124+
assert req._writer is not None
1125+
await req._writer
11241126
await t
11251127
# assert conn.close.called
11261128
assert conn.protocol.set_exception.called

0 commit comments

Comments
 (0)