Skip to content

Commit 4939c1c

Browse files
authored
chore(benchmark): don't fill benchmark tests by default (#1920)
* chore(benchmark): don't fill benchmark tests by default. * chore(benchmark): change to collection level only. * chore: optimizations via review. * chore(tests): pr comments.
1 parent ae95b1b commit 4939c1c

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

tests/benchmark/conftest.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@
77

88
def pytest_collection_modifyitems(config, items):
99
"""Add the `benchmark` marker to all tests under `./tests/benchmark`."""
10-
for item in items:
11-
if Path(__file__).parent in Path(item.fspath).parents:
12-
item.add_marker(pytest.mark.benchmark)
10+
marker_expr = config.getoption("-m", default="")
11+
gas_benchmark_values = config.getoption("--gas-benchmark-values", default=None)
12+
run_benchmarks = marker_expr and (
13+
"benchmark" in marker_expr and "not benchmark" not in marker_expr
14+
)
15+
if gas_benchmark_values:
16+
run_benchmarks = True
17+
items_for_removal = []
18+
for i, item in enumerate(items):
19+
is_in_benchmark_dir = Path(__file__).parent in Path(item.fspath).parents
20+
has_benchmark_marker = item.get_closest_marker("benchmark") is not None
21+
is_benchmark_test = is_in_benchmark_dir or has_benchmark_marker
22+
if is_benchmark_test:
23+
if is_in_benchmark_dir and not has_benchmark_marker:
24+
benchmark_marker = pytest.mark.benchmark
25+
26+
item.add_marker(benchmark_marker)
27+
if not run_benchmarks:
28+
items_for_removal.append(i)
29+
30+
elif run_benchmarks:
31+
items_for_removal.append(i)
32+
33+
for i in reversed(items_for_removal):
34+
items.pop(i)

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ description = Fill test cases in ./tests/ for deployed mainnet forks, except for
8383
setenv =
8484
# Use custom EELS_RESOLUTIONS_FILE if it is set via the environment (eg, in CI)
8585
EELS_RESOLUTIONS_FILE = {env:EELS_RESOLUTIONS_FILE:}
86-
commands = fill -n auto -m "not slow and not benchmark" --output=/tmp/fixtures-tox --clean
86+
commands = fill -n auto -m "not slow" --output=/tmp/fixtures-tox --clean
8787

8888
[testenv:tests-deployed-benchmark]
8989
description = Fill benchmarking test cases in ./tests/ for deployed mainnet forks, using evmone-t8n.
@@ -94,7 +94,7 @@ description = Fill test cases in ./tests/ for deployed and development mainnet f
9494
setenv =
9595
# Use custom EELS_RESOLUTIONS_FILE if it is set via the environment (eg, in CI)
9696
EELS_RESOLUTIONS_FILE = {env:EELS_RESOLUTIONS_FILE:}
97-
commands = fill -n auto --until={[forks]develop} -k "not slow and not benchmark" --output=/tmp/fixtures-tox --clean
97+
commands = fill -n auto --until={[forks]develop} -k "not slow" --output=/tmp/fixtures-tox --clean
9898

9999
# ----------------------------------------------------------------------------------------------
100100
# ALIAS ENVIRONMENTS

0 commit comments

Comments
 (0)