Skip to content

Commit 2a6f9ee

Browse files
refactor(test-benchmark): repricing filter logic (#1810)
* refactor: update filter logic * fix: fixed opcode count logic * chore: update comment * refactor: add negate logic
1 parent 120b1be commit 2a6f9ee

File tree

3 files changed

+32
-27
lines changed

3 files changed

+32
-27
lines changed

packages/testing/src/execution_testing/cli/pytest_commands/plugins/shared/benchmarking.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,16 @@ def pytest_configure(config: pytest.Config) -> None:
4444
def pytest_collection_modifyitems(
4545
config: pytest.Config, items: list[pytest.Item]
4646
) -> None:
47-
"""Remove non-repricing tests when --fixed-opcode-count is specified."""
47+
"""Filter tests based on repricing marker"""
48+
gas_benchmark_value = config.getoption("gas_benchmark_value")
4849
fixed_opcode_count = config.getoption("fixed_opcode_count")
49-
if not fixed_opcode_count:
50-
# If --fixed-opcode-count is not specified, don't filter anything
50+
51+
if not gas_benchmark_value and not fixed_opcode_count:
52+
return
53+
54+
# Check if -m repricing marker filter was specified
55+
markexpr = config.getoption("markexpr", "")
56+
if "repricing" not in markexpr or "not repricing" in markexpr:
5157
return
5258

5359
filtered = []
@@ -105,27 +111,22 @@ def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
105111
)
106112

107113
if "fixed_opcode_count" in metafunc.fixturenames:
108-
# Only parametrize if test has repricing marker
109-
has_repricing = (
110-
metafunc.definition.get_closest_marker("repricing") is not None
111-
)
112-
if has_repricing:
113-
if fixed_opcode_counts:
114-
opcode_counts = [
115-
int(x.strip()) for x in fixed_opcode_counts.split(",")
116-
]
117-
opcode_count_parameters = [
118-
pytest.param(
119-
opcode_count,
120-
id=f"opcount_{opcode_count}K",
121-
)
122-
for opcode_count in opcode_counts
123-
]
124-
metafunc.parametrize(
125-
"fixed_opcode_count",
126-
opcode_count_parameters,
127-
scope="function",
114+
if fixed_opcode_counts:
115+
opcode_counts = [
116+
int(x.strip()) for x in fixed_opcode_counts.split(",")
117+
]
118+
opcode_count_parameters = [
119+
pytest.param(
120+
opcode_count,
121+
id=f"opcount_{opcode_count}K",
128122
)
123+
for opcode_count in opcode_counts
124+
]
125+
metafunc.parametrize(
126+
"fixed_opcode_count",
127+
opcode_count_parameters,
128+
scope="function",
129+
)
129130

130131

131132
@pytest.fixture(scope="function")

packages/testing/src/execution_testing/specs/benchmark.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ def model_post_init(self, __context: Any, /) -> None:
248248

249249
blocks: List[Block] = self.setup_blocks
250250

251+
if self.fixed_opcode_count is not None and self.code_generator is None:
252+
pytest.skip(
253+
"Cannot run fixed opcode count tests without a code generator"
254+
)
255+
251256
if self.code_generator is not None:
252257
# Inject fixed_opcode_count into the code generator if provided
253258
self.code_generator.fixed_opcode_count = self.fixed_opcode_count

tests/benchmark/conftest.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@ def pytest_collection_modifyitems(config: Any, items: Any) -> None:
4949
return
5050

5151
marker_expr = config.getoption("-m", default="")
52+
5253
run_benchmarks = (
53-
marker_expr
54-
and "benchmark" in marker_expr
55-
and "not benchmark" not in marker_expr
56-
)
54+
"benchmark" in marker_expr and "not benchmark" not in marker_expr
55+
) or ("repricing" in marker_expr and "not repricing" not in marker_expr)
5756
run_stateful_tests = (
5857
marker_expr
5958
and "stateful" in marker_expr

0 commit comments

Comments
 (0)