Skip to content

Commit 9773440

Browse files
feat: add state marker
1 parent 9f96fad commit 9773440

File tree

6 files changed

+85
-4
lines changed

6 files changed

+85
-4
lines changed

src/pytest_plugins/shared/execute_fill.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ def pytest_configure(config: pytest.Config):
9696
"markers",
9797
"benchmark: Tests relevant to benchmarking EVMs.",
9898
)
99+
config.addinivalue_line(
100+
"markers",
101+
"state: Tests for stateful benchmarking scenarios.",
102+
)
99103
config.addinivalue_line(
100104
"markers",
101105
"exception_test: Negative tests that include an invalid block or transaction.",

tests/benchmark/conftest.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,27 @@ def pytest_collection_modifyitems(config, items):
3333

3434
if gen_docs:
3535
for item in items:
36-
if benchmark_dir in Path(item.fspath).parents and not item.get_closest_marker(
37-
"benchmark"
36+
if (
37+
benchmark_dir in Path(item.fspath).parents
38+
and not item.get_closest_marker("benchmark")
39+
and not item.get_closest_marker("state")
3840
):
3941
item.add_marker(benchmark_marker)
4042
return
4143

4244
marker_expr = config.getoption("-m", default="")
4345
run_benchmarks = (
4446
marker_expr and "benchmark" in marker_expr and "not benchmark" not in marker_expr
45-
) or config.getoption("--gas-benchmark-values", default=None)
47+
)
48+
run_state_tests = marker_expr and "state" in marker_expr and "not state" not in marker_expr
4649

4750
items_for_removal = []
4851
for i, item in enumerate(items):
4952
is_in_benchmark_dir = benchmark_dir in Path(item.fspath).parents
50-
is_benchmark_test = is_in_benchmark_dir or item.get_closest_marker("benchmark")
53+
has_state_marker = item.get_closest_marker("state")
54+
is_benchmark_test = (
55+
is_in_benchmark_dir and not has_state_marker
56+
) or item.get_closest_marker("benchmark")
5157

5258
if is_benchmark_test:
5359
if is_in_benchmark_dir and not item.get_closest_marker("benchmark"):
@@ -56,6 +62,8 @@ def pytest_collection_modifyitems(config, items):
5662
items_for_removal.append(i)
5763
elif run_benchmarks:
5864
items_for_removal.append(i)
65+
elif is_in_benchmark_dir and has_state_marker and not run_state_tests:
66+
items_for_removal.append(i)
5967

6068
for i in reversed(items_for_removal):
6169
items.pop(i)

tests/benchmark/state/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Benchmark state tests package."""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Bloatnet benchmark tests package."""
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""
2+
abstract: Tests benchmark worst-case bloatnet scenarios.
3+
Tests benchmark worst-case bloatnet scenarios.
4+
5+
Tests running worst-case bloatnet scenarios for benchmarking purposes.
6+
"""

tests/benchmark/state/conftest.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
"""Pytest configuration for state tests."""
2+
3+
from pathlib import Path
4+
5+
import pytest
6+
7+
DEFAULT_BENCHMARK_FORK = "Prague"
8+
9+
10+
def pytest_generate_tests(metafunc):
11+
"""Add default valid_from marker to state tests without explicit fork specification."""
12+
state_dir = Path(__file__).parent
13+
test_file_path = Path(metafunc.definition.fspath)
14+
15+
if state_dir in test_file_path.parents:
16+
has_valid_from = any(
17+
marker.name == "valid_from" for marker in metafunc.definition.iter_markers()
18+
)
19+
if not has_valid_from:
20+
metafunc.definition.add_marker(pytest.mark.valid_from(DEFAULT_BENCHMARK_FORK))
21+
22+
23+
def pytest_collection_modifyitems(config, items):
24+
"""Manage state test markers and filtering."""
25+
state_dir = Path(__file__).parent
26+
gen_docs = config.getoption("--gen-docs", default=False)
27+
28+
if gen_docs:
29+
_add_state_markers_for_docs(items, state_dir)
30+
return
31+
32+
marker_expr = config.getoption("-m", default="")
33+
34+
items_to_remove = []
35+
36+
for i, item in enumerate(items):
37+
item_path = Path(item.fspath)
38+
is_in_state_dir = state_dir in item_path.parents
39+
40+
# Add state marker to tests in state directory that don't have it
41+
if is_in_state_dir and not item.get_closest_marker("state"):
42+
item.add_marker(pytest.mark.state)
43+
44+
has_state_marker = item.get_closest_marker("state")
45+
46+
run_state = marker_expr and ("state" in marker_expr) and ("not state" not in marker_expr)
47+
48+
# When not running state tests, remove all state tests
49+
if not run_state and has_state_marker:
50+
items_to_remove.append(i)
51+
52+
for i in reversed(items_to_remove):
53+
items.pop(i)
54+
55+
56+
def _add_state_markers_for_docs(items, state_dir):
57+
"""Add state markers for documentation generation."""
58+
for item in items:
59+
item_path = Path(item.fspath)
60+
if state_dir in item_path.parents and not item.get_closest_marker("state"):
61+
item.add_marker(pytest.mark.state)

0 commit comments

Comments
 (0)