Skip to content

Commit a4a41d2

Browse files
committed
Merge branch 'optimize-test-collection' into benchmark_v0.0.3
2 parents 6fcfbe0 + ded78c6 commit a4a41d2

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/pytest_plugins/execute/execute.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,25 +349,28 @@ def pytest_generate_tests(metafunc: pytest.Metafunc):
349349

350350
def pytest_collection_modifyitems(config: pytest.Config, items: List[pytest.Item]):
351351
"""Remove transition tests and add the appropriate execute markers to the test."""
352-
for item in items[:]: # use a copy of the list, as we'll be modifying it
352+
i = 0
353+
while i < len(items):
354+
item = items[i]
353355
if isinstance(item, EIPSpecTestItem):
354356
continue
355357
params: Dict[str, Any] = item.callspec.params # type: ignore
356358
if "fork" not in params or params["fork"] is None:
357-
items.remove(item)
359+
items.pop(i)
358360
continue
359361
fork: Fork = params["fork"]
360362
spec_type, execute_format = get_spec_format_for_item(params)
361363
assert issubclass(execute_format, BaseExecute)
362364
markers = list(item.iter_markers())
363365
if spec_type.discard_execute_format_by_marks(execute_format, fork, markers):
364-
items.remove(item)
366+
items.pop(i)
365367
continue
366368
for marker in markers:
367369
if marker.name == "execute":
368370
for mark in marker.args:
369371
item.add_marker(mark)
370372
elif marker.name == "valid_at_transition_to":
371-
items.remove(item)
373+
items.pop(i)
372374
if "yul" in item.fixturenames: # type: ignore
373375
item.add_marker(pytest.mark.yul_test)
376+
i += 1

src/pytest_plugins/filler/filler.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,27 +1106,29 @@ def pytest_collection_modifyitems(
11061106
These can't be handled in this plugins pytest_generate_tests() as the fork
11071107
parametrization occurs in the forks plugin.
11081108
"""
1109-
for item in items[:]: # use a copy of the list, as we'll be modifying it
1109+
i = 0
1110+
while i < len(items):
1111+
item = items[i]
11101112
params: Dict[str, Any] | None = None
11111113
if isinstance(item, pytest.Function):
11121114
params = item.callspec.params
11131115
elif hasattr(item, "params"):
11141116
params = item.params
11151117
if not params or "fork" not in params or params["fork"] is None:
1116-
items.remove(item)
1118+
items.pop(i)
11171119
continue
11181120
fork: Fork = params["fork"]
11191121
spec_type, fixture_format = get_spec_format_for_item(params)
11201122
if isinstance(fixture_format, NotSetType):
1121-
items.remove(item)
1123+
items.pop(i)
11221124
continue
11231125
assert issubclass(fixture_format, BaseFixture)
11241126
if not fixture_format.supports_fork(fork):
1125-
items.remove(item)
1127+
items.pop(i)
11261128
continue
11271129
markers = list(item.iter_markers())
11281130
if spec_type.discard_fixture_format_by_marks(fixture_format, fork, markers):
1129-
items.remove(item)
1131+
items.pop(i)
11301132
continue
11311133
for marker in markers:
11321134
if marker.name == "fill":
@@ -1147,6 +1149,7 @@ def pytest_collection_modifyitems(
11471149
f"fork_{fork.name()}",
11481150
f"fork_{base_fork.name()}",
11491151
)
1152+
i += 1
11501153

11511154

11521155
def pytest_sessionfinish(session: pytest.Session, exitstatus: int):

0 commit comments

Comments
 (0)