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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ exclude = [
"^fixtures/",
"^logs/",
"^site/",
"^tests/json_infra/fixtures/",
]
plugins = ["pydantic.mypy"]

Expand Down
33 changes: 33 additions & 0 deletions tests/json_infra/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def pytest_addoption(parser: Parser) -> None:
type=str,
help="Run tests from and including the specified fork.",
)

parser.addoption(
"--until",
action="store",
Expand All @@ -88,13 +89,15 @@ def pytest_addoption(parser: Parser) -> None:
type=str,
help="Run tests until and including the specified fork.",
)

parser.addoption(
"--fork",
action="store",
dest="single_fork",
default="",
help="Only run tests for the specified fork.",
)

parser.addoption(
"--file-list",
action="store",
Expand All @@ -106,6 +109,13 @@ def pytest_addoption(parser: Parser) -> None:
),
)

parser.addoption(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these options might end up contradicting each other. For example, we might have --fork=Frontier and the tests file might have an entry called tests/json_infra/fixtures/latest_fork_tests/fixtures/state_tests/berlin/eip2930_access_list/test_account_storage_warm_cold_state.json::tests/berlin/eip2930_access_list/test_acl.py::test_account_storage_warm_cold_state[fork_Shanghai-state_test-account_warm_True-storage_key_warm_True]::Shanghai::0 which is from Shanghai.

In this set-up, the Shanghai tests will not run. Is this what is intended? Alternatively, we could just make it invalid to pair the --tests-file option with the others.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes sense. If I'm not mistaken, the following command wouldn't run any tests either, so this behaviour is consistent.

pytest --fork=Frontier \
    'tests/json_infra/fixtures/latest_fork_tests/fixtures/state_tests/berlin/eip2930_access_list/test_account_storage_warm_cold_state.json::tests/berlin/eip2930_access_list/test_acl.py::test_account_storage_warm_cold_state[fork_Shanghai-state_test-account_warm_True-storage_key_warm_True]::Shanghai::0'

"--tests-file",
dest="tests_path",
type=Path,
help="Path to a file containing test ids, one per line",
)


def pytest_configure(config: Config) -> None:
"""
Expand Down Expand Up @@ -175,6 +185,29 @@ def pytest_configure(config: Config) -> None:
config.stash[desired_forks_key] = desired_forks


def pytest_collection_modifyitems(config: Config, items: list[Item]) -> None:
"""Filter test items."""
tests_path = config.getoption("tests_path", None)
if tests_path is None:
return

with open(tests_path) as f:
test_ids = set(x.removesuffix("\n") for x in f.readlines())

selected = []
deselected = []
for item in items:
if item.nodeid in test_ids:
selected.append(item)
test_ids.remove(item.nodeid)
else:
deselected.append(item)

if deselected:
config.hook.pytest_deselected(items=deselected)
items[:] = selected # keep only what matches


class _FixturesDownloader:
cache: Final[SQLiteCache]
session: Final[CachedSession]
Expand Down
6 changes: 6 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ commands =
pytest \
-n auto --maxprocesses 6 \
--basetemp="{temp_dir}/pytest" \
{posargs} \
src

[testenv:tests_pytest_pypy3]
Expand All @@ -57,6 +58,7 @@ commands =
pytest \
-n auto --maxprocesses 6 \
--basetemp="{temp_dir}/pytest" \
{posargs} \
src

[testenv:json_infra]
Expand Down Expand Up @@ -85,6 +87,7 @@ commands =
--log-to "{toxworkdir}/logs" \
--clean \
--until Osaka \
{posargs} \
tests

[testenv:pypy3]
Expand All @@ -108,6 +111,7 @@ commands =
--log-to "{toxworkdir}/logs" \
--clean \
--until Osaka \
{posargs} \
tests

[testenv:benchmark]
Expand All @@ -123,6 +127,7 @@ commands =
--log-to "{toxworkdir}/logs" \
--clean \
--fork Prague \
{posargs} \
tests/benchmark

[testenv:optimized]
Expand All @@ -137,6 +142,7 @@ commands =
--ignore-glob='tests/test_t8n.py' \
--basetemp="{temp_dir}/pytest" \
--optimized \
{posargs} \
tests/json_infra

[testenv:spec-docs]
Expand Down
Loading