Skip to content

Commit

Permalink
Speed up test suite with pytest-xdist
Browse files Browse the repository at this point in the history
  • Loading branch information
Kludex committed Dec 14, 2024
1 parent a3cc360 commit bab2932
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ disallow_untyped_defs = false
check_untyped_defs = true

[tool.pytest.ini_options]
addopts = "-rxXs --strict-config --strict-markers"
addopts = "-rxXs --strict-config --strict-markers -n 8"
xfail_strict = true
filterwarnings = [
"error",
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ twine==5.1.1
ruff==0.7.1
pytest==8.3.3
pytest-mock==3.14.0
pytest-xdist[psutil]==3.6.0
mypy==1.13.0
types-click==7.1.8
types-pyyaml==6.0.12.20240917
Expand All @@ -25,6 +26,7 @@ cryptography==43.0.3
coverage==7.6.1; python_version < '3.9'
coverage==7.6.4; python_version >= '3.9'
coverage-conditional-plugin==0.9.0
coverage-enable-subprocess==1.0
httpx==0.27.2
watchgod==0.8.2

Expand Down
2 changes: 2 additions & 0 deletions scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ if [ -z $GITHUB_ACTIONS ]; then
scripts/check
fi

export COVERAGE_PROCESS_START=$(pwd)/pyproject.toml

${PREFIX}coverage run --debug config -m pytest "$@"

if [ -z $GITHUB_ACTIONS ]; then
Expand Down
6 changes: 4 additions & 2 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ async def app(scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable
@pytest.mark.parametrize("exception_signal", signals)
@pytest.mark.parametrize("capture_signal", signal_captures)
async def test_server_interrupt(
exception_signal: signal.Signals, capture_signal: Callable[[signal.Signals], ContextManager[None]]
exception_signal: signal.Signals,
capture_signal: Callable[[signal.Signals], ContextManager[None]],
unused_tcp_port: int,
): # pragma: py-win32
"""Test interrupting a Server that is run explicitly inside asyncio"""

Expand All @@ -71,7 +73,7 @@ async def interrupt_running(srv: Server):
await asyncio.sleep(0.01)
signal.raise_signal(exception_signal)

server = Server(Config(app=dummy_app, loop="asyncio"))
server = Server(Config(app=dummy_app, loop="asyncio", port=unused_tcp_port))
asyncio.create_task(interrupt_running(server))
with capture_signal(exception_signal) as witness:
await server.serve()
Expand Down

0 comments on commit bab2932

Please sign in to comment.