Skip to content

Commit 389d25a

Browse files
committed
chore(tests): read test list from file
1 parent 522b320 commit 389d25a

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

tests/json_infra/conftest.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def pytest_addoption(parser: Parser) -> None:
8080
type=str,
8181
help="Run tests from and including the specified fork.",
8282
)
83+
8384
parser.addoption(
8485
"--until",
8586
action="store",
@@ -88,13 +89,15 @@ def pytest_addoption(parser: Parser) -> None:
8889
type=str,
8990
help="Run tests until and including the specified fork.",
9091
)
92+
9193
parser.addoption(
9294
"--fork",
9395
action="store",
9496
dest="single_fork",
9597
default="",
9698
help="Only run tests for the specified fork.",
9799
)
100+
98101
parser.addoption(
99102
"--file-list",
100103
action="store",
@@ -106,6 +109,13 @@ def pytest_addoption(parser: Parser) -> None:
106109
),
107110
)
108111

112+
parser.addoption(
113+
"--tests-file",
114+
dest="tests_path",
115+
type=Path,
116+
help="Path to a file containing test ids, one per line",
117+
)
118+
109119

110120
def pytest_configure(config: Config) -> None:
111121
"""
@@ -175,6 +185,29 @@ def pytest_configure(config: Config) -> None:
175185
config.stash[desired_forks_key] = desired_forks
176186

177187

188+
def pytest_collection_modifyitems(config: Config, items: list[Item]) -> None:
189+
"""Filter test items."""
190+
tests_path = config.getoption("tests_path", None)
191+
if tests_path is None:
192+
return
193+
194+
with open(tests_path) as f:
195+
test_ids = set(x[:-1] for x in f.readlines())
196+
197+
selected = []
198+
deselected = []
199+
for item in items:
200+
if item.nodeid in test_ids:
201+
selected.append(item)
202+
test_ids.remove(item.nodeid)
203+
else:
204+
deselected.append(item)
205+
206+
if deselected:
207+
config.hook.pytest_deselected(items=deselected)
208+
items[:] = selected # keep only what matches
209+
210+
178211
class _FixturesDownloader:
179212
cache: Final[SQLiteCache]
180213
session: Final[CachedSession]

tox.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ commands =
3939
pytest \
4040
-n auto --maxprocesses 6 \
4141
--basetemp="{temp_dir}/pytest" \
42+
{posargs} \
4243
src
4344

4445
[testenv:tests_pytest_pypy3]
@@ -57,6 +58,7 @@ commands =
5758
pytest \
5859
-n auto --maxprocesses 6 \
5960
--basetemp="{temp_dir}/pytest" \
61+
{posargs} \
6062
src
6163

6264
[testenv:json_infra]
@@ -85,6 +87,7 @@ commands =
8587
--log-to "{toxworkdir}/logs" \
8688
--clean \
8789
--until Osaka \
90+
{posargs} \
8891
tests
8992

9093
[testenv:pypy3]
@@ -108,6 +111,7 @@ commands =
108111
--log-to "{toxworkdir}/logs" \
109112
--clean \
110113
--until Osaka \
114+
{posargs} \
111115
tests
112116

113117
[testenv:benchmark]
@@ -123,6 +127,7 @@ commands =
123127
--log-to "{toxworkdir}/logs" \
124128
--clean \
125129
--fork Prague \
130+
{posargs} \
126131
tests/benchmark
127132

128133
[testenv:optimized]
@@ -137,6 +142,7 @@ commands =
137142
--ignore-glob='tests/test_t8n.py' \
138143
--basetemp="{temp_dir}/pytest" \
139144
--optimized \
145+
{posargs} \
140146
tests/json_infra
141147

142148
[testenv:spec-docs]

0 commit comments

Comments
 (0)