Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/templates/base.md.j2
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Documentation for [`{{ pytest_node_id }}@{{ short_git_ref }}`]({{ source_code_ur
```console
{% if is_benchmark %}
fill -v {{ pytest_node_id }} -m benchmark
{% elif is_stateful %}
fill -v {{ pytest_node_id }} -m stateful
{% else %}
fill -v {{ pytest_node_id }} --fork {{ target_or_valid_fork }}
{% endif %}
Expand Down
13 changes: 12 additions & 1 deletion src/pytest_plugins/filler/gen_test_doc/gen_test_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ def create_function_page_props(self, test_functions: Dict["str", List[Item]]) ->
)

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

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

def create_module_page_props(self) -> None:
Expand All @@ -462,6 +464,7 @@ def create_module_page_props(self) -> None:
pytest_node_id=str(module_path),
package_name=get_import_path(module_path),
is_benchmark=function_page.is_benchmark,
is_stateful=function_page.is_stateful,
test_functions=[
TestFunction(
name=function_page.title,
Expand All @@ -475,6 +478,8 @@ def create_module_page_props(self) -> None:
existing_module_page = self.module_page_props[str(function_page.path)]
if function_page.is_benchmark:
existing_module_page.is_benchmark = True
if function_page.is_stateful:
existing_module_page.is_stateful = True
existing_module_page.test_functions.append(
TestFunction(
name=function_page.title,
Expand Down Expand Up @@ -511,7 +516,12 @@ def add_directory_page_props(self) -> None:
is_benchmark = any(
module_page.is_benchmark
for module_page in self.module_page_props.values()
if module_page.path.parent == directory
if directory in module_page.path.parents or module_page.path.parent == directory
)
is_stateful = any(
module_page.is_stateful
for module_page in self.module_page_props.values()
if directory in module_page.path.parents or module_page.path.parent == directory
)

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

def find_files_within_collection_scope(self, file_pattern: str) -> List[Path]:
Expand Down
1 change: 1 addition & 0 deletions src/pytest_plugins/filler/gen_test_doc/page_props.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class PagePropsBase:
pytest_node_id: str
package_name: str
is_benchmark: bool = False
is_stateful: bool = False

@property
@abstractmethod
Expand Down
4 changes: 4 additions & 0 deletions src/pytest_plugins/shared/execute_fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ def pytest_configure(config: pytest.Config):
"markers",
"benchmark: Tests relevant to benchmarking EVMs.",
)
config.addinivalue_line(
"markers",
"stateful: Tests for stateful benchmarking scenarios.",
)
config.addinivalue_line(
"markers",
"exception_test: Negative tests that include an invalid block or transaction.",
Expand Down
1 change: 0 additions & 1 deletion tests/benchmark/bloatnet/__init__.py

This file was deleted.

18 changes: 14 additions & 4 deletions tests/benchmark/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,29 @@ def pytest_collection_modifyitems(config, items):

if gen_docs:
for item in items:
if benchmark_dir in Path(item.fspath).parents and not item.get_closest_marker(
"benchmark"
if (
benchmark_dir in Path(item.fspath).parents
and not item.get_closest_marker("benchmark")
and not item.get_closest_marker("stateful")
):
item.add_marker(benchmark_marker)
return

marker_expr = config.getoption("-m", default="")
run_benchmarks = (
marker_expr and "benchmark" in marker_expr and "not benchmark" not in marker_expr
) or config.getoption("--gas-benchmark-values", default=None)
)
run_stateful_tests = (
marker_expr and "stateful" in marker_expr and "not stateful" not in marker_expr
)

items_for_removal = []
for i, item in enumerate(items):
is_in_benchmark_dir = benchmark_dir in Path(item.fspath).parents
is_benchmark_test = is_in_benchmark_dir or item.get_closest_marker("benchmark")
has_stateful_marker = item.get_closest_marker("stateful")
is_benchmark_test = (
is_in_benchmark_dir and not has_stateful_marker
) or item.get_closest_marker("benchmark")

if is_benchmark_test:
if is_in_benchmark_dir and not item.get_closest_marker("benchmark"):
Expand All @@ -61,6 +69,8 @@ def pytest_collection_modifyitems(config, items):
items_for_removal.append(i)
elif run_benchmarks:
items_for_removal.append(i)
elif is_in_benchmark_dir and has_stateful_marker and not run_stateful_tests:
items_for_removal.append(i)

for i in reversed(items_for_removal):
items.pop(i)
Expand Down
1 change: 1 addition & 0 deletions tests/benchmark/stateful/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Benchmark state tests package."""
1 change: 1 addition & 0 deletions tests/benchmark/stateful/bloatnet/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Bloatnet benchmark tests package."""
6 changes: 6 additions & 0 deletions tests/benchmark/stateful/bloatnet/test_bloatnet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""
abstract: Tests benchmark worst-case bloatnet scenarios.
Tests benchmark worst-case bloatnet scenarios.

Tests running worst-case bloatnet scenarios for benchmarking purposes.
"""
66 changes: 66 additions & 0 deletions tests/benchmark/stateful/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""Pytest configuration for state tests."""

from pathlib import Path

import pytest

DEFAULT_BENCHMARK_FORK = "Prague"


def pytest_generate_tests(metafunc):
"""
Add default valid_from marker to state tests without explicit fork
specification.
"""
state_dir = Path(__file__).parent
test_file_path = Path(metafunc.definition.fspath)

if state_dir in test_file_path.parents:
has_valid_from = any(
marker.name == "valid_from" for marker in metafunc.definition.iter_markers()
)
if not has_valid_from:
metafunc.definition.add_marker(pytest.mark.valid_from(DEFAULT_BENCHMARK_FORK))


def pytest_collection_modifyitems(config, items):
"""Manage stateful test markers and filtering."""
state_dir = Path(__file__).parent
gen_docs = config.getoption("--gen-docs", default=False)

if gen_docs:
_add_stateful_markers_for_docs(items, state_dir)
return

marker_expr = config.getoption("-m", default="")

items_to_remove = []

for i, item in enumerate(items):
item_path = Path(item.fspath)
is_in_state_dir = state_dir in item_path.parents

# Add stateful marker to tests in state directory that don't have it
if is_in_state_dir and not item.get_closest_marker("stateful"):
item.add_marker(pytest.mark.stateful)

has_stateful_marker = item.get_closest_marker("stateful")

run_stateful = (
marker_expr and ("stateful" in marker_expr) and ("not stateful" not in marker_expr)
)

# When not running stateful tests, remove all stateful tests
if not run_stateful and has_stateful_marker:
items_to_remove.append(i)

for i in reversed(items_to_remove):
items.pop(i)


def _add_stateful_markers_for_docs(items, state_dir):
"""Add stateful markers for documentation generation."""
for item in items:
item_path = Path(item.fspath)
if state_dir in item_path.parents and not item.get_closest_marker("stateful"):
item.add_marker(pytest.mark.stateful)
Loading