Skip to content

Commit b4ca90b

Browse files
committed
Ensure state test test against intended fork only
The statetest fixtures have different definitions for each fork and we must ensure to only run test against against the intended fork (e.g run Constantinople state tests against Constantinople VM). We can not rely on `pytest -k` matching for that as that matches against an identification string that includes the path and name of the test file which in some cases also contains fork names. A test file may be named "ConstantinopleSomething.json" but still contains individual definitions per fork.
1 parent 32238c7 commit b4ca90b

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

eth/tools/fixtures/loading.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def load_fixture(fixture_path: str,
7777
def filter_fixtures(all_fixtures: Iterable[Any],
7878
fixtures_base_dir: str,
7979
mark_fn: Callable[[str, str], bool]=None,
80-
ignore_fn: Callable[[str, str], bool]=None) -> Any:
80+
ignore_fn: Callable[..., bool]=None) -> Any:
8181
"""
8282
Helper function for filtering test fixtures.
8383

tests/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,7 @@ def chain_without_block_validation(
186186
}
187187
chain = klass.from_genesis(base_db, genesis_params, genesis_state)
188188
return chain
189+
190+
191+
def pytest_addoption(parser):
192+
parser.addoption("--fork", type=str, required=False)

tests/json-fixtures/test_state.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,33 @@ def mark_statetest_fixtures(fixture_path, fixture_key, fixture_fork, fixture_ind
162162
return pytest.mark.xfail(reason="Listed in INCORRECT_UPSTREAM_TESTS.")
163163

164164

165+
def generate_ignore_fn_for_fork(metafunc):
166+
"""
167+
The statetest fixtures have different definitions for each fork and we must ensure to only run
168+
test against against the intended fork (e.g run Constantinople state tests against
169+
Constantinople VM).
170+
We can not rely on `pytest -k` matching for that as that matches against an identification
171+
string that includes the path and name of the test which in some cases also contains fork
172+
fork names. A test file may be named "ConstantinopleSomething.json" but still contains
173+
individual definitions per fork.
174+
"""
175+
passed_fork = metafunc.config.getoption('fork')
176+
if passed_fork:
177+
passed_fork = passed_fork.lower()
178+
179+
def ignore_fn(fixture_path, fixture_key, fixture_fork, post_state_index):
180+
return fixture_fork.lower() != passed_fork
181+
182+
return ignore_fn
183+
184+
165185
def pytest_generate_tests(metafunc):
166186
generate_fixture_tests(
167187
metafunc=metafunc,
168188
base_fixture_path=BASE_FIXTURE_PATH,
169189
preprocess_fn=expand_fixtures_forks,
170190
filter_fn=filter_fixtures(
191+
ignore_fn=generate_ignore_fn_for_fork(metafunc),
171192
fixtures_base_dir=BASE_FIXTURE_PATH,
172193
mark_fn=mark_statetest_fixtures,
173194
),

tox.ini

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ commands=
3636
transactions: pytest {posargs:tests/json-fixtures/test_transactions.py}
3737
vm: pytest {posargs:tests/json-fixtures/test_virtual_machine.py}
3838
native-blockchain: pytest {posargs:tests/json-fixtures/test_blockchain.py}
39-
native-state-frontier: pytest {posargs:tests/json-fixtures/test_state.py -k Frontier}
40-
native-state-homestead: pytest {posargs:tests/json-fixtures/test_state.py -k Homestead}
41-
native-state-eip150: pytest {posargs:tests/json-fixtures/test_state.py -k EIP150}
42-
native-state-eip158: pytest {posargs:tests/json-fixtures/test_state.py -k EIP158}
43-
native-state-byzantium: pytest {posargs:tests/json-fixtures/test_state.py -k Byzantium}
44-
native-state-constantinople: pytest {posargs:tests/json-fixtures/test_state.py -k Constantinople}
45-
native-state-metropolis: pytest {posargs:tests/json-fixtures/test_state.py -k Metropolis}
39+
native-state-frontier: pytest {posargs:tests/json-fixtures/test_state.py --fork Frontier}
40+
native-state-homestead: pytest {posargs:tests/json-fixtures/test_state.py --fork Homestead}
41+
native-state-eip150: pytest {posargs:tests/json-fixtures/test_state.py --fork EIP150}
42+
native-state-eip158: pytest {posargs:tests/json-fixtures/test_state.py --fork EIP158}
43+
native-state-byzantium: pytest {posargs:tests/json-fixtures/test_state.py --fork Byzantium}
44+
native-state-constantinople: pytest {posargs:tests/json-fixtures/test_state.py --fork Constantinople}
45+
native-state-metropolis: pytest {posargs:tests/json-fixtures/test_state.py --fork Metropolis}
4646
lightchain_integration: pytest --integration {posargs:tests/trinity/integration/test_lightchain_integration.py}
4747

4848
deps = .[p2p,trinity,eth-extra,test]

0 commit comments

Comments
 (0)