Skip to content

Commit 10b0204

Browse files
feat(benchmarks): add bloatnet marker support (#2169)
Co-authored-by: Mario Vega <[email protected]>
1 parent 77edf42 commit 10b0204

File tree

11 files changed

+107
-6
lines changed

11 files changed

+107
-6
lines changed

docs/templates/base.md.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Documentation for [`{{ pytest_node_id }}@{{ short_git_ref }}`]({{ source_code_ur
1111
```console
1212
{% if is_benchmark %}
1313
fill -v {{ pytest_node_id }} -m benchmark
14+
{% elif is_stateful %}
15+
fill -v {{ pytest_node_id }} -m stateful
1416
{% else %}
1517
fill -v {{ pytest_node_id }} --fork {{ target_or_valid_fork }}
1618
{% endif %}

src/pytest_plugins/filler/gen_test_doc/gen_test_doc.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ def create_function_page_props(self, test_functions: Dict["str", List[Item]]) ->
431431
)
432432

433433
is_benchmark = items[0].get_closest_marker("benchmark") is not None
434+
is_stateful = items[0].get_closest_marker("stateful") is not None
434435

435436
self.function_page_props[function_id] = FunctionPageProps(
436437
title=get_test_function_name(items[0]),
@@ -447,6 +448,7 @@ def create_function_page_props(self, test_functions: Dict["str", List[Item]]) ->
447448
html_static_page_target=f"./{get_test_function_name(items[0])}.html",
448449
mkdocs_function_page_target=f"./{get_test_function_name(items[0])}/",
449450
is_benchmark=is_benchmark,
451+
is_stateful=is_stateful,
450452
)
451453

452454
def create_module_page_props(self) -> None:
@@ -462,6 +464,7 @@ def create_module_page_props(self) -> None:
462464
pytest_node_id=str(module_path),
463465
package_name=get_import_path(module_path),
464466
is_benchmark=function_page.is_benchmark,
467+
is_stateful=function_page.is_stateful,
465468
test_functions=[
466469
TestFunction(
467470
name=function_page.title,
@@ -475,6 +478,8 @@ def create_module_page_props(self) -> None:
475478
existing_module_page = self.module_page_props[str(function_page.path)]
476479
if function_page.is_benchmark:
477480
existing_module_page.is_benchmark = True
481+
if function_page.is_stateful:
482+
existing_module_page.is_stateful = True
478483
existing_module_page.test_functions.append(
479484
TestFunction(
480485
name=function_page.title,
@@ -511,7 +516,12 @@ def add_directory_page_props(self) -> None:
511516
is_benchmark = any(
512517
module_page.is_benchmark
513518
for module_page in self.module_page_props.values()
514-
if module_page.path.parent == directory
519+
if directory in module_page.path.parents or module_page.path.parent == directory
520+
)
521+
is_stateful = any(
522+
module_page.is_stateful
523+
for module_page in self.module_page_props.values()
524+
if directory in module_page.path.parents or module_page.path.parent == directory
515525
)
516526

517527
self.page_props[str(directory)] = DirectoryPageProps(
@@ -526,6 +536,7 @@ def add_directory_page_props(self) -> None:
526536
# init.py will be used for docstrings
527537
package_name=get_import_path(directory),
528538
is_benchmark=is_benchmark,
539+
is_stateful=is_stateful,
529540
)
530541

531542
def find_files_within_collection_scope(self, file_pattern: str) -> List[Path]:

src/pytest_plugins/filler/gen_test_doc/page_props.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class PagePropsBase:
111111
pytest_node_id: str
112112
package_name: str
113113
is_benchmark: bool = False
114+
is_stateful: bool = False
114115

115116
@property
116117
@abstractmethod

src/pytest_plugins/shared/execute_fill.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ def pytest_configure(config: pytest.Config):
100100
"markers",
101101
"benchmark: Tests relevant to benchmarking EVMs.",
102102
)
103+
config.addinivalue_line(
104+
"markers",
105+
"stateful: Tests for stateful benchmarking scenarios.",
106+
)
103107
config.addinivalue_line(
104108
"markers",
105109
"exception_test: Negative tests that include an invalid block or transaction.",

tests/benchmark/bloatnet/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/benchmark/conftest.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,29 @@ def pytest_collection_modifyitems(config, items):
3838

3939
if gen_docs:
4040
for item in items:
41-
if benchmark_dir in Path(item.fspath).parents and not item.get_closest_marker(
42-
"benchmark"
41+
if (
42+
benchmark_dir in Path(item.fspath).parents
43+
and not item.get_closest_marker("benchmark")
44+
and not item.get_closest_marker("stateful")
4345
):
4446
item.add_marker(benchmark_marker)
4547
return
4648

4749
marker_expr = config.getoption("-m", default="")
4850
run_benchmarks = (
4951
marker_expr and "benchmark" in marker_expr and "not benchmark" not in marker_expr
50-
) or config.getoption("--gas-benchmark-values", default=None)
52+
)
53+
run_stateful_tests = (
54+
marker_expr and "stateful" in marker_expr and "not stateful" not in marker_expr
55+
)
5156

5257
items_for_removal = []
5358
for i, item in enumerate(items):
5459
is_in_benchmark_dir = benchmark_dir in Path(item.fspath).parents
55-
is_benchmark_test = is_in_benchmark_dir or item.get_closest_marker("benchmark")
60+
has_stateful_marker = item.get_closest_marker("stateful")
61+
is_benchmark_test = (
62+
is_in_benchmark_dir and not has_stateful_marker
63+
) or item.get_closest_marker("benchmark")
5664

5765
if is_benchmark_test:
5866
if is_in_benchmark_dir and not item.get_closest_marker("benchmark"):
@@ -61,6 +69,8 @@ def pytest_collection_modifyitems(config, items):
6169
items_for_removal.append(i)
6270
elif run_benchmarks:
6371
items_for_removal.append(i)
72+
elif is_in_benchmark_dir and has_stateful_marker and not run_stateful_tests:
73+
items_for_removal.append(i)
6474

6575
for i in reversed(items_for_removal):
6676
items.pop(i)
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+
"""
File renamed without changes.

0 commit comments

Comments
 (0)