Skip to content

Commit 7e4e6ce

Browse files
authored
Free-threading: run with pytest-run-paralell (#507)
1 parent 6100b9c commit 7e4e6ce

File tree

5 files changed

+50
-10
lines changed

5 files changed

+50
-10
lines changed

.github/workflows/tests.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ jobs:
3535
python-version: ${{ matrix.python }}
3636
allow-prereleases: true
3737
- run: uv run --locked tox run -e ${{ matrix.tox || format('py{0}', matrix.python) }}
38+
- if: endsWith(matrix.python, 't')
39+
run: uv run --locked tox run -e parallel
3840
typing:
3941
runs-on: ubuntu-latest
4042
steps:

pyproject.toml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pre-commit = [
4848
]
4949
tests = [
5050
"pytest",
51+
"pytest-run-parallel; python_full_version >= '3.13'",
5152
]
5253
typing = [
5354
"mypy",
@@ -67,7 +68,10 @@ testpaths = ["tests"]
6768
filterwarnings = [
6869
"error",
6970
]
70-
71+
markers = [
72+
# Needed when pytest-run-parallel is not installed
73+
"thread_unsafe: mark test as not safe to run in multiple threads",
74+
]
7175
[tool.coverage.run]
7276
branch = true
7377
source = ["markupsafe", "tests"]
@@ -124,8 +128,8 @@ tag-only = [
124128

125129
[tool.tox]
126130
env_list = [
127-
"py3.14", "py3.14t", "py3.13", "py3.13t",
128-
"py3.12", "py3.11", "py3.10", "py3.9",
131+
"py3.14", "py3.14t", "parallel",
132+
"py3.13", "py3.13t", "py3.12", "py3.11", "py3.10", "py3.9",
129133
"pypy3.11",
130134
"style",
131135
"typing",
@@ -145,6 +149,15 @@ commands = [[
145149
{replace = "posargs", default = [], extend = true},
146150
]]
147151

152+
[tool.tox.env.parallel]
153+
description = "check for free threading issues"
154+
base_python = ["3.14t"]
155+
commands = [[
156+
"pytest", "-v", "--tb=short", "--basetemp=env_tmp_dir",
157+
"--parallel-threads=8",
158+
{replace = "posargs", default = [], extend = true},
159+
]]
160+
148161
[tool.tox.env.style]
149162
description = "run all pre-commit hooks on all files"
150163
dependency_groups = ["pre-commit"]

tests/test_ext_init.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
_speedups = None # type: ignore[assignment]
1111

1212

13+
@pytest.mark.thread_unsafe(reason="Tampers with sys.modules")
1314
@pytest.mark.skipif(_speedups is None, reason="speedups unavailable")
1415
def test_ext_init() -> None:
1516
"""Test that the extension module uses multi-phase init by checking that

tests/test_leak.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
import gc
44

5+
import pytest
6+
57
from markupsafe import escape
68

79

10+
@pytest.mark.thread_unsafe(reason="Tests gc.get_objects()")
811
def test_markup_leaks() -> None:
912
counts = set()
1013
# Try to start with a "clean" count. Works for PyPy but not 3.13 JIT.

uv.lock

Lines changed: 28 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)