Skip to content

Commit 712f16e

Browse files
committed
ci/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 137e287 commit 712f16e

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
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.mainnet import (
@@ -201,7 +202,7 @@ def fixture_transaction_in_rpc_format(state):
201202
}
202203

203204

204-
def blockchain_fixture_mark_fn(fixture_path, fixture_name):
205+
def blockchain_fixture_mark_fn(fixture_path, fixture_name, fixture_fork):
205206
for slow_test in SLOW_TESTS:
206207
if slow_test in fixture_path or slow_test in fixture_name:
207208
if not should_run_slow_tests():
@@ -211,13 +212,35 @@ def blockchain_fixture_mark_fn(fixture_path, fixture_name):
211212
return pytest.mark.xfail(reason="Listed in INCORRECT_UPSTREAM_TESTS.")
212213

213214

215+
# TODO: import from `py-evm` if possible?..
216+
def generate_ignore_fn_for_fork(passed_fork):
217+
if passed_fork:
218+
passed_fork = passed_fork.lower()
219+
220+
def ignore_fn(fixture_path, fixture_key, fixture_fork):
221+
return fixture_fork.lower() != passed_fork
222+
223+
return ignore_fn
224+
225+
226+
# TODO: import from `py-evm` if possible?..
227+
@to_tuple
228+
def expand_fixtures_forks(all_fixtures):
229+
for fixture_path, fixture_key in all_fixtures:
230+
fixture = load_fixture(fixture_path, fixture_key)
231+
yield fixture_path, fixture_key, fixture['network']
232+
233+
214234
def pytest_generate_tests(metafunc):
235+
ignore_fn = generate_ignore_fn_for_fork(metafunc.config.getoption('fork'))
215236
generate_fixture_tests(
216237
metafunc=metafunc,
217238
base_fixture_path=BASE_FIXTURE_PATH,
239+
preprocess_fn=expand_fixtures_forks,
218240
filter_fn=filter_fixtures(
219241
fixtures_base_dir=BASE_FIXTURE_PATH,
220242
mark_fn=blockchain_fixture_mark_fn,
243+
ignore_fn=ignore_fn
221244
),
222245
)
223246

@@ -398,8 +421,9 @@ async def validate_uncles(rpc, block_fixture, at_block):
398421

399422
@pytest.fixture
400423
def chain_fixture(fixture_data):
401-
fixture = load_fixture(*fixture_data)
402-
if fixture['network'] == 'Istanbul':
424+
fixture_path, fixture_key, fixture_fork = fixture_data
425+
fixture = load_fixture(fixture_path, fixture_key)
426+
if fixture_fork == 'Istanbul':
403427
pytest.skip('Istanbul VM rules not yet supported')
404428
return fixture
405429

tox.ini

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@ commands=
2626
p2p: pytest -n 4 {posargs:tests/p2p}
2727
plugins: pytest -n 4 {posargs:tests/plugins/}
2828
rpc-blockchain: pytest -n 4 {posargs:tests/json-fixtures-over-rpc/test_rpc_fixtures.py -k 'not GeneralStateTests'}
29-
rpc-state-frontier: pytest -n 4 {posargs:tests/json-fixtures-over-rpc/test_rpc_fixtures.py -k 'GeneralStateTests and not stQuadraticComplexityTest and Frontier'}
30-
rpc-state-homestead: pytest -n 4 {posargs:tests/json-fixtures-over-rpc/test_rpc_fixtures.py -k 'GeneralStateTests and not stQuadraticComplexityTest and Homestead'}
31-
rpc-state-tangerine_whistle: pytest -n 4 {posargs:tests/json-fixtures-over-rpc/test_rpc_fixtures.py -k 'GeneralStateTests and not stQuadraticComplexityTest and EIP150'}
32-
rpc-state-spurious_dragon: pytest -n 4 {posargs:tests/json-fixtures-over-rpc/test_rpc_fixtures.py -k 'GeneralStateTests and not stQuadraticComplexityTest and EIP158'}
29+
rpc-state-frontier: pytest -n 4 {posargs:tests/json-fixtures-over-rpc/test_rpc_fixtures.py --fork Frontier -k 'GeneralStateTests and not stQuadraticComplexityTest'}
30+
rpc-state-homestead: pytest -n 4 {posargs:tests/json-fixtures-over-rpc/test_rpc_fixtures.py --fork Homestead -k 'GeneralStateTests and not stQuadraticComplexityTest'}
31+
rpc-state-tangerine_whistle: pytest -n 4 {posargs:tests/json-fixtures-over-rpc/test_rpc_fixtures.py --fork EIP150 -k 'GeneralStateTests and not stQuadraticComplexityTest'}
32+
rpc-state-spurious_dragon: pytest -n 4 {posargs:tests/json-fixtures-over-rpc/test_rpc_fixtures.py --fork EIP158 -k 'GeneralStateTests and not stQuadraticComplexityTest'}
3333
# The following test seems to consume a lot of memory. Restricting to 3 processes reduces crashes
34-
rpc-state-byzantium: pytest -n 3 {posargs:tests/json-fixtures-over-rpc/test_rpc_fixtures.py -k 'GeneralStateTests and not stQuadraticComplexityTest and Byzantium'}
35-
# Must match Constantinople but not ConstantinopleFix!
36-
rpc-state-constantinople: pytest -n 3 {posargs:tests/json-fixtures-over-rpc/test_rpc_fixtures.py -k 'GeneralStateTests and not stQuadraticComplexityTest and not ConstantinopleFix and Constantinople'}
37-
rpc-state-petersburg: pytest -n 3 {posargs:tests/json-fixtures-over-rpc/test_rpc_fixtures.py -k 'GeneralStateTests and not stQuadraticComplexityTest and ConstantinopleFix'}
34+
rpc-state-byzantium: pytest -n 3 {posargs:tests/json-fixtures-over-rpc/test_rpc_fixtures.py --fork Byzantium -k 'GeneralStateTests and not stQuadraticComplexityTest'}
35+
rpc-state-constantinople: pytest -n 3 {posargs:tests/json-fixtures-over-rpc/test_rpc_fixtures.py --fork Constantinople -k 'GeneralStateTests and not stQuadraticComplexityTest'}
36+
rpc-state-petersburg: pytest -n 3 {posargs:tests/json-fixtures-over-rpc/test_rpc_fixtures.py --fork ConstantinopleFix -k 'GeneralStateTests and not stQuadraticComplexityTest'}
3837
rpc-state-quadratic: pytest -n 4 {posargs:tests/json-fixtures-over-rpc/test_rpc_fixtures.py -k 'GeneralStateTests and stQuadraticComplexityTest'}
3938
lightchain_integration: pytest --integration {posargs:tests/integration/test_lightchain_integration.py}
4039

0 commit comments

Comments
 (0)