Skip to content

Commit f05cc83

Browse files
authored
chore(tests/asgi): skip Uvicorn tests when testing other ASGI servers (#2737)
* chore(tests/asgi): skip Uvicorn tests when testing other ASGI servers * chore(facepalm): windoze and their CRLF... * chore(CI): use cpython 3.14 as the default version for tests * chore(CI): migrate more things 3.12 -> 3.14 Comment out Firefox E2E gate again: still broken.
1 parent 966bf9c commit f05cc83

7 files changed

Lines changed: 97 additions & 54 deletions

File tree

‎.github/workflows/cibuildwheel.yaml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Set up Python
2828
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
2929
with:
30-
python-version: "3.12"
30+
python-version: "3.14"
3131

3232
- name: Build sdist and pure-Python wheel
3333
env:
@@ -79,7 +79,7 @@ jobs:
7979
- name: Set up Python
8080
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
8181
with:
82-
python-version: "3.12"
82+
python-version: "3.14"
8383

8484
- name: Download artifacts
8585
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
@@ -251,7 +251,7 @@ jobs:
251251
- name: Set up Python
252252
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
253253
with:
254-
python-version: "3.12"
254+
python-version: "3.14"
255255

256256
- name: Download artifacts
257257
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1

‎.github/workflows/test-dist.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- name: Set up Python
2929
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
3030
with:
31-
python-version: "3.12"
31+
python-version: "3.14"
3232

3333
- name: Build dist
3434
env:

‎.github/workflows/tests.yaml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
default-os:
2525
- "ubuntu-latest"
2626
python-version:
27-
- "3.12"
27+
- "3.14"
2828
tox:
2929
# Lint
3030
- env: pep8
@@ -52,7 +52,6 @@ jobs:
5252
- env: py311_cython
5353
python-version: "3.11"
5454
- env: py312
55-
coverage: true
5655
python-version: "3.12"
5756
- env: py312_cython
5857
python-version: "3.12"
@@ -61,17 +60,18 @@ jobs:
6160
- env: py313_cython
6261
python-version: "3.13"
6362
- env: py314
63+
coverage: true
6464
python-version: "3.14"
6565
- env: py314_cython
6666
python-version: "3.14"
6767
- env: py315
6868
python-version: "3.15.0-rc.2 - 3.15.0"
6969
- env: py315_cython
7070
python-version: "3.15.0-rc.2 - 3.15.0"
71-
- env: py312_nocover
71+
- env: py314_nocover
7272
os: macos-latest
7373
platform-label: ' (macos)'
74-
- env: py312_nocover
74+
- env: py314_nocover
7575
os: windows-latest
7676
platform-label: ' (windows)'
7777
# Tutorials

‎requirements/asgiservers‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# NOTE(vytas): These are the requirements to run ASGI server integration tests,
2+
# but not the servers themselves. Tox environments specify them instead.
3+
4+
pytest >= 7.0
5+
httpx
6+
requests
7+
websockets >= 13.1

‎tests/asgi/_asgi_test_app.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
from collections import Counter
33
import hashlib
4+
import pathlib
45
import platform
56
import sys
67
import time
@@ -10,6 +11,9 @@
1011
import falcon.errors
1112
import falcon.util
1213

14+
HERE = pathlib.Path(__file__).resolve().parent
15+
FALCON_ROOT = HERE.parent.parent
16+
1317
SSE_TEST_MAX_DELAY_SEC = 1
1418
_WIN32 = sys.platform.startswith('win')
1519
_X86_64 = platform.machine() == 'x86_64'
@@ -301,6 +305,8 @@ def create_app():
301305
app.add_route('/feeds/{feed_id}', Feed())
302306
app.add_route('/wsoptions', WSOptions(app.ws_options))
303307

308+
app.add_static_route('/static', FALCON_ROOT, downloadable=True)
309+
304310
app.add_middleware(lifespan_handler)
305311

306312
async def _on_ws_error(req, resp, error, params, ws=None):

‎tests/asgi/test_asgi_servers.py‎

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,46 @@ async def emitter():
196196
assert resp.json().get('drops') >= 1
197197

198198

199+
class TestStaticFiles:
200+
def test_get(self, server_base_url, requests):
201+
expected = (_asgi_test_app.FALCON_ROOT / 'LICENSE').read_bytes()
202+
203+
resp = requests.get(
204+
server_base_url + 'static/LICENSE', timeout=_REQUEST_TIMEOUT
205+
)
206+
assert resp.status_code == 200
207+
assert resp.content == expected
208+
209+
range_resp = requests.get(
210+
server_base_url + 'static/LICENSE',
211+
headers={'Range': 'bytes=13-37'},
212+
timeout=_REQUEST_TIMEOUT,
213+
)
214+
assert range_resp.status_code == 206
215+
assert range_resp.content == expected[13 : 37 + 1]
216+
217+
def test_not_modified(self, server_base_url, requests):
218+
resp1 = requests.get(
219+
server_base_url + 'static/README.rst', timeout=_REQUEST_TIMEOUT
220+
)
221+
assert resp1.status_code == 200
222+
223+
etag = resp1.headers.get('ETag')
224+
assert etag, 'missing ETag header'
225+
assert (
226+
resp1.headers.get('Content-Disposition')
227+
== 'attachment; filename="README.rst"'
228+
)
229+
assert resp1.headers.get('Last-Modified'), 'missing Last-Modified header'
230+
231+
resp2 = requests.get(
232+
server_base_url + 'static/README.rst',
233+
headers={'If-None-Match': etag},
234+
timeout=_REQUEST_TIMEOUT,
235+
)
236+
assert resp2.status_code == 304
237+
238+
199239
@pytest.mark.skipif(
200240
websockets is None, reason='websockets is required for this test class'
201241
)
@@ -607,39 +647,28 @@ def _hypercorn_factory(host, port):
607647
)
608648

609649

610-
def _can_run(factory):
611-
if _WIN32 and factory == _daphne_factory:
650+
@pytest.fixture(params=['daphne', 'granian', 'hypercorn', 'uvicorn'])
651+
def asgi_server(request):
652+
if _WIN32 and request.param == 'daphne':
612653
pytest.skip('daphne does not support windows')
654+
return request.param
613655

614-
if factory == _daphne_factory:
615-
try:
616-
import daphne # noqa
617-
except Exception:
618-
pytest.skip('daphne not installed')
619-
elif factory == _hypercorn_factory:
620-
try:
621-
import hypercorn # noqa
622-
except Exception:
623-
pytest.skip('hypercorn not installed')
624-
elif factory == _uvicorn_factory:
625-
try:
626-
import uvicorn # noqa
627-
except Exception:
628-
pytest.skip('uvicorn not installed')
629-
elif factory == _granian_factory:
630-
try:
631-
import granian # noqa
632-
except Exception:
633-
pytest.skip('granian not installed')
634656

657+
@pytest.fixture()
658+
def process_factory(asgi_server):
659+
pytest.importorskip(asgi_server)
660+
661+
servers = {
662+
'daphne': _daphne_factory,
663+
'granian': _granian_factory,
664+
'hypercorn': _hypercorn_factory,
665+
'uvicorn': _uvicorn_factory,
666+
}
667+
return servers[asgi_server]
635668

636-
@pytest.fixture(
637-
params=[_uvicorn_factory, _daphne_factory, _granian_factory, _hypercorn_factory]
638-
)
639-
def server_base_url(request, requests):
640-
process_factory = request.param
641-
_can_run(process_factory)
642669

670+
@pytest.fixture()
671+
def server_base_url(requests, process_factory):
643672
for i in range(3):
644673
server_port = testing.get_unused_port()
645674
base_url = f'http://{_SERVER_HOST}:{server_port}/'

‎tox.ini‎

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
# --------------------------------------------------------------------
44
#
5-
# NOTE(kgriffs,vytas): Python 3.10, 3.11, 3.12, or 3.13 are required
6-
# when checking combined coverage. To check coverage:
5+
# NOTE(kgriffs,vytas): CPython 3.10-3.15 is required when checking
6+
# combined coverage. To check coverage:
77
#
88
# $ tox
99
#
@@ -72,16 +72,16 @@ deps = {[testenv]deps}
7272
testtools
7373
commands = coverage run -m pytest tests []
7474

75-
[testenv:py312]
76-
basepython = python3.12
75+
[testenv:py314]
76+
basepython = python3.14
7777
deps = {[testenv]deps}
7878
pytest-randomly
7979
jsonschema
8080
testtools
8181
commands = {[with-coverage]commands}
8282

83-
[testenv:py312_nocover]
84-
basepython = python3.12
83+
[testenv:py314_nocover]
84+
basepython = python3.14
8585
deps = {[testenv]deps}
8686
pytest-randomly
8787
jsonschema
@@ -103,7 +103,7 @@ deps = -r{toxinidir}/requirements/tests
103103
pdbpp
104104

105105
[testenv:py3_debug]
106-
basepython = python3.12
106+
basepython = python3.14
107107
deps = {[with-debug-tools]deps}
108108
uvicorn
109109
jsonschema
@@ -214,6 +214,7 @@ commands = {[with-cython]commands}
214214

215215
[testenv:wsgi_servers]
216216
setenv = {[with-cython]setenv}
217+
# NOTE(vytas): Uvicorn is also included (via default deps) and tested.
217218
deps = {[with-cython]deps}
218219
cheroot
219220
granian
@@ -236,17 +237,17 @@ commands = pytest -v tests/test_wsgi_servers.py
236237
# --------------------------------------------------------------------
237238

238239
[testenv:daphne]
239-
deps = {[testenv]deps}
240+
deps = -r{toxinidir}/requirements/asgiservers
240241
daphne
241242
commands = pytest -v tests/asgi/test_asgi_servers.py
242243

243244
[testenv:granian]
244-
deps = {[testenv]deps}
245+
deps = -r{toxinidir}/requirements/asgiservers
245246
granian
246247
commands = pytest -v tests/asgi/test_asgi_servers.py
247248

248249
[testenv:hypercorn]
249-
deps = {[testenv]deps}
250+
deps = -r{toxinidir}/requirements/asgiservers
250251
hypercorn
251252
commands = pytest -v tests/asgi/test_asgi_servers.py
252253

@@ -279,25 +280,25 @@ commands = {[smoke-test]commands}
279280
# --------------------------------------------------------------------
280281

281282
[testenv:pep8]
282-
deps = ruff>=0.11.6
283+
deps = ruff>=0.16.7
283284
skip_install = True
284285
commands = ruff check []
285286

286287
[testenv:pep8-docstrings]
287-
deps = ruff>=0.11.6
288+
deps = ruff>=0.16.7
288289
skip_install = True
289290
commands = ruff check \
290291
--exclude=.ecosystem,.eggs,.git,.tox,.venv,build,dist,docs,examples,tests,falcon/bench/nuts \
291292
--select=D205,D212,D400,D401,D403,D404 \
292293
[]
293294

294295
[testenv:ruff]
295-
deps = ruff>=0.11.6
296+
deps = ruff>=0.16.7
296297
skip_install = True
297298
commands = ruff format --check . []
298299

299300
[testenv:reformat]
300-
deps = ruff>=0.11.6
301+
deps = ruff>=0.16.7
301302
skip_install = True
302303
commands =
303304
ruff format . []
@@ -423,7 +424,7 @@ commands =
423424
pytest {toxinidir}/examples/look/tests
424425

425426
[testenv:asgilook]
426-
basepython = python3.12
427+
basepython = python3.14
427428
deps =
428429
-r{toxinidir}/examples/asgilook/requirements/asgilook
429430
-r{toxinidir}/examples/asgilook/requirements/test
@@ -436,7 +437,7 @@ commands =
436437
{toxinidir}/examples/asgilook/tests/
437438

438439
[testenv:ws_tutorial]
439-
basepython = python3.12
440+
basepython = python3.14
440441
deps =
441442
-r{toxinidir}/examples/ws_tutorial/requirements/app
442443
-r{toxinidir}/examples/ws_tutorial/requirements/test
@@ -453,14 +454,14 @@ commands =
453454
# --------------------------------------------------------------------
454455

455456
[testenv:e2e_chrome]
456-
basepython = python3.12
457+
basepython = python3.14
457458
deps =
458459
-r{toxinidir}/requirements/e2e
459460
commands =
460461
pytest {toxinidir}/e2e-tests/ --browser=chrome
461462

462463
[testenv:e2e_firefox]
463-
basepython = python3.12
464+
basepython = python3.14
464465
deps =
465466
-r{toxinidir}/requirements/e2e
466467
commands =

0 commit comments

Comments
 (0)