Skip to content

Commit c141e31

Browse files
committed
tests: ignore tests not matching --fork arg given to pytest.
Mostly a copy-paste from `py-evm` codebase; relevant PRs that introduced the functionality there: ethereum/py-evm#1470 ethereum/py-evm#1577
1 parent 56ea99f commit c141e31

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

tests/json-fixtures-over-rpc/test_rpc_fixtures.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
is_hex,
1717
is_integer,
1818
is_string,
19+
to_tuple,
1920
)
2021

2122
from eth.chains.base import (
@@ -204,7 +205,7 @@ def fixture_transaction_in_rpc_format(state):
204205
}
205206

206207

207-
def blockchain_fixture_mark_fn(fixture_path, fixture_name):
208+
def blockchain_fixture_mark_fn(fixture_path, fixture_name, fixture_fork):
208209
for slow_test in SLOW_TESTS:
209210
if slow_test in fixture_path or slow_test in fixture_name:
210211
if not should_run_slow_tests():
@@ -214,13 +215,35 @@ def blockchain_fixture_mark_fn(fixture_path, fixture_name):
214215
return pytest.mark.xfail(reason="Listed in INCORRECT_UPSTREAM_TESTS.")
215216

216217

218+
# TODO: import from `py-evm` if possible?..
219+
def generate_ignore_fn_for_fork(passed_fork):
220+
if passed_fork:
221+
passed_fork = passed_fork.lower()
222+
223+
def ignore_fn(fixture_path, fixture_key, fixture_fork):
224+
return fixture_fork.lower() != passed_fork
225+
226+
return ignore_fn
227+
228+
229+
# TODO: import from `py-evm` if possible?..
230+
@to_tuple
231+
def expand_fixtures_forks(all_fixtures):
232+
for fixture_path, fixture_key in all_fixtures:
233+
fixture = load_fixture(fixture_path, fixture_key)
234+
yield fixture_path, fixture_key, fixture['network']
235+
236+
217237
def pytest_generate_tests(metafunc):
238+
ignore_fn=generate_ignore_fn_for_fork(metafunc.config.getoption('fork'))
218239
generate_fixture_tests(
219240
metafunc=metafunc,
220241
base_fixture_path=BASE_FIXTURE_PATH,
242+
preprocess_fn=expand_fixtures_forks,
221243
filter_fn=filter_fixtures(
222244
fixtures_base_dir=BASE_FIXTURE_PATH,
223245
mark_fn=blockchain_fixture_mark_fn,
246+
ignore_fn=ignore_fn
224247
),
225248
)
226249

@@ -401,8 +424,9 @@ async def validate_uncles(rpc, block_fixture, at_block):
401424

402425
@pytest.fixture
403426
def chain_fixture(fixture_data):
404-
fixture = load_fixture(*fixture_data)
405-
if fixture['network'] == 'Istanbul':
427+
fixture_path, fixture_key, fixture_fork = fixture_data
428+
fixture = load_fixture(fixture_path, fixture_key)
429+
if fixture_fork == 'Istanbul':
406430
pytest.skip('Istanbul VM rules not yet supported')
407431
return fixture
408432

0 commit comments

Comments
 (0)