Skip to content

Commit 3c8499d

Browse files
committed
chore(tests): read test list from file
1 parent 1e99293 commit 3c8499d

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

tests/json_infra/conftest.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ def pytest_addoption(parser: Parser) -> None:
7272
help="Run tests for this fork only (e.g., --fork Osaka)",
7373
)
7474

75+
parser.addoption(
76+
"--tests-file",
77+
dest="tests_path",
78+
type=Path,
79+
help="Path to a file containing test ids, one per line",
80+
)
81+
7582

7683
def pytest_configure(config: Config) -> None:
7784
"""
@@ -92,8 +99,7 @@ def pytest_configure(config: Config) -> None:
9299
ethereum.trace.set_evm_trace(Eip3155Tracer())
93100

94101

95-
def pytest_collection_modifyitems(config: Config, items: list[Item]) -> None:
96-
"""Filter test items based on the specified fork option."""
102+
def _fork_collection_modifyitems(config: Config, items: list[Item]) -> None:
97103
desired_fork = config.getoption("fork", None)
98104
if not desired_fork:
99105
return
@@ -125,6 +131,36 @@ def pytest_collection_modifyitems(config: Config, items: list[Item]) -> None:
125131
items[:] = selected # keep only what matches
126132

127133

134+
def _tests_path_collection_modifyitems(
135+
config: Config, items: list[Item]
136+
) -> None:
137+
tests_path = config.getoption("tests_path", None)
138+
if tests_path is None:
139+
return
140+
141+
with open(tests_path) as f:
142+
test_ids = set(x[:-1] for x in f.readlines())
143+
144+
selected = []
145+
deselected = []
146+
for item in items:
147+
if item.nodeid in test_ids:
148+
selected.append(item)
149+
test_ids.remove(item.nodeid)
150+
else:
151+
deselected.append(item)
152+
153+
if deselected:
154+
config.hook.pytest_deselected(items=deselected)
155+
items[:] = selected # keep only what matches
156+
157+
158+
def pytest_collection_modifyitems(config: Config, items: list[Item]) -> None:
159+
"""Filter test items."""
160+
_fork_collection_modifyitems(config, items)
161+
_tests_path_collection_modifyitems(config, items)
162+
163+
128164
class _FixturesDownloader:
129165
cache: Final[SQLiteCache]
130166
session: Final[CachedSession]

tox.ini

Lines changed: 7 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]
@@ -73,6 +75,7 @@ commands =
7375
--cov-branch \
7476
--ignore-glob='tests/json_infra/fixtures/*' \
7577
--basetemp="{temp_dir}/pytest" \
78+
{posargs} \
7679
tests/json_infra
7780

7881
[testenv:py3]
@@ -85,6 +88,7 @@ commands =
8588
--log-to "{toxworkdir}/logs" \
8689
--clean \
8790
--until Osaka \
91+
{posargs} \
8892
tests
8993

9094
[testenv:pypy3]
@@ -108,6 +112,7 @@ commands =
108112
--log-to "{toxworkdir}/logs" \
109113
--clean \
110114
--until Osaka \
115+
{posargs} \
111116
tests
112117

113118
[testenv:benchmark]
@@ -123,6 +128,7 @@ commands =
123128
--log-to "{toxworkdir}/logs" \
124129
--clean \
125130
--fork Prague \
131+
{posargs} \
126132
tests/benchmark
127133

128134
[testenv:optimized]
@@ -138,6 +144,7 @@ commands =
138144
--ignore-glob='tests/test_t8n.py' \
139145
--basetemp="{temp_dir}/pytest" \
140146
--optimized \
147+
{posargs} \
141148
tests/json_infra
142149

143150
[testenv:spec-docs]

0 commit comments

Comments
 (0)