Skip to content

Commit b5aa703

Browse files
committed
tests: rely on pytest-asyncio
1 parent 47fd273 commit b5aa703

File tree

2 files changed

+23
-32
lines changed

2 files changed

+23
-32
lines changed

pyproject.toml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ dependencies = [
5757
[project.optional-dependencies]
5858
test = [
5959
"pytest",
60+
"pytest-asyncio",
6061
"pytest-cov",
6162
"pytest-html",
6263
]
@@ -195,21 +196,33 @@ src = "pyproject.toml"
195196
[[tool.tbump.file]]
196197
src = "labextension/package.json"
197198

199+
200+
# pytest is used for running Python based tests
201+
#
202+
# ref: https://docs.pytest.org/en/stable/
203+
#
198204
[tool.pytest.ini_options]
199-
cache_dir = "build/.cache/pytest"
200-
testpaths = ["tests"]
201205
addopts = [
202-
"-vv",
206+
"--verbose",
207+
"--durations=10",
208+
"--color=yes",
203209
"--cov=jupyter_server_proxy",
204210
"--cov-branch",
205211
"--cov-context=test",
206212
"--cov-report=term-missing:skip-covered",
207213
"--cov-report=html:build/coverage",
208214
"--no-cov-on-fail",
209215
"--html=build/pytest/index.html",
210-
"--color=yes",
211216
]
217+
asyncio_mode = "auto"
218+
testpaths = ["tests"]
219+
cache_dir = "build/.cache/pytest"
212220

221+
222+
# pytest-cov / coverage is used to measure code coverage of tests
223+
#
224+
# ref: https://coverage.readthedocs.io/en/stable/config.html
225+
#
213226
[tool.coverage.run]
214227
data_file = "build/.coverage"
215228
concurrency = [

tests/test_proxies.py

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
import gzip
32
import json
43
import sys
@@ -332,14 +331,9 @@ def test_server_content_encoding_header(
332331
assert f.read() == b"this is a test"
333332

334333

335-
@pytest.fixture(scope="module")
336-
def event_loop():
337-
loop = asyncio.get_event_loop()
338-
yield loop
339-
loop.close()
340-
341-
342-
async def _websocket_echo(a_server_port_and_token: Tuple[int, str]) -> None:
334+
async def test_server_proxy_websocket_messages(
335+
a_server_port_and_token: Tuple[int, str]
336+
) -> None:
343337
PORT = a_server_port_and_token[0]
344338
url = f"ws://{LOCALHOST}:{PORT}/python-websocket/echosocket"
345339
conn = await websocket_connect(url)
@@ -349,13 +343,7 @@ async def _websocket_echo(a_server_port_and_token: Tuple[int, str]) -> None:
349343
assert msg == expected_msg
350344

351345

352-
def test_server_proxy_websocket(
353-
event_loop, a_server_port_and_token: Tuple[int, str]
354-
) -> None:
355-
event_loop.run_until_complete(_websocket_echo(a_server_port_and_token))
356-
357-
358-
async def _websocket_headers(a_server_port_and_token: Tuple[int, str]) -> None:
346+
async def test_server_proxy_websocket_headers(a_server_port_and_token: Tuple[int, str]):
359347
PORT = a_server_port_and_token[0]
360348
url = f"ws://{LOCALHOST}:{PORT}/python-websocket/headerssocket"
361349
conn = await websocket_connect(url)
@@ -366,13 +354,9 @@ async def _websocket_headers(a_server_port_and_token: Tuple[int, str]) -> None:
366354
assert headers["X-Custom-Header"] == "pytest-23456"
367355

368356

369-
def test_server_proxy_websocket_headers(
370-
event_loop, a_server_port_and_token: Tuple[int, str]
357+
async def test_server_proxy_websocket_subprotocols(
358+
a_server_port_and_token: Tuple[int, str]
371359
):
372-
event_loop.run_until_complete(_websocket_headers(a_server_port_and_token))
373-
374-
375-
async def _websocket_subprotocols(a_server_port_and_token: Tuple[int, str]) -> None:
376360
PORT, TOKEN = a_server_port_and_token
377361
url = f"ws://{LOCALHOST}:{PORT}/python-websocket/subprotocolsocket"
378362
conn = await websocket_connect(url, subprotocols=["protocol_1", "protocol_2"])
@@ -381,12 +365,6 @@ async def _websocket_subprotocols(a_server_port_and_token: Tuple[int, str]) -> N
381365
assert json.loads(msg) == ["protocol_1"]
382366

383367

384-
def test_server_proxy_websocket_subprotocols(
385-
event_loop, a_server_port_and_token: Tuple[int, str]
386-
):
387-
event_loop.run_until_complete(_websocket_subprotocols(a_server_port_and_token))
388-
389-
390368
@pytest.mark.parametrize(
391369
"proxy_path, status",
392370
[

0 commit comments

Comments
 (0)