Skip to content

Commit 3664399

Browse files
committed
refactor: Make test ids better
1 parent 8eeda4a commit 3664399

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

src/pytest_plugins/consume/consume.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,5 +506,8 @@ def pytest_generate_tests(metafunc):
506506
metafunc.parametrize("test_case", param_list)
507507

508508
if "client_type" in metafunc.fixturenames:
509-
client_ids = [client.name for client in metafunc.config.hive_execution_clients]
510-
metafunc.parametrize("client_type", metafunc.config.hive_execution_clients, ids=client_ids)
509+
metafunc.parametrize(
510+
"client_type",
511+
metafunc.config.hive_execution_clients,
512+
ids=[client.name for client in metafunc.config.hive_execution_clients],
513+
)

src/pytest_plugins/consume/simulators/sync/conftest.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,49 @@ def pytest_generate_tests(metafunc):
4141
)
4242

4343

44+
@pytest.hookimpl(trylast=True)
45+
def pytest_collection_modifyitems(session, config, items):
46+
"""Modify test IDs to show both client and sync client clearly."""
47+
for item in items:
48+
# Check if this test has both client_type and sync_client_type
49+
if (
50+
hasattr(item, "callspec")
51+
and "client_type" in item.callspec.params
52+
and "sync_client_type" in item.callspec.params
53+
):
54+
# Get the client names and remove fork suffix if present
55+
client_name = item.callspec.params["client_type"].name.replace("-", "_")
56+
sync_client_name = item.callspec.params["sync_client_type"].name.replace("-", "_")
57+
58+
# Format: ``-{client}_sync_{sync_client}``
59+
new_suffix = f"-{client_name}::sync_{sync_client_name}"
60+
61+
# client_param-tests/path/to/test.py::test_name[test_params]-sync_client_param
62+
# 1. Remove the client prefix from the beginning
63+
# 2. Replace the -client_param part at the end with our new format
64+
nodeid = item.nodeid
65+
prefix_index = item.nodeid.find("-tests/")
66+
if prefix_index != -1:
67+
nodeid = item.nodeid[prefix_index + 1 :]
68+
69+
# Find the last hyphen followed by client name pattern and replace
70+
if "-" in nodeid:
71+
# Split by the last hyphen to separate the client suffix
72+
parts = nodeid.rsplit("]-", 1)
73+
assert len(parts) == 2, (
74+
# expect "..._end_of_test]-client_name" suffix...
75+
f"Unexpected format to parse client name: {nodeid}"
76+
)
77+
78+
base = parts[0]
79+
if base.endswith("sync_test"):
80+
# Insert suffix before the closing bracket
81+
base = base + new_suffix + "]"
82+
item._nodeid = base
83+
else:
84+
item._nodeid = base + new_suffix
85+
86+
4487
@pytest.fixture(scope="function")
4588
def engine_rpc(client: Client, client_exception_mapper: ExceptionMapper | None) -> EngineRPC:
4689
"""Initialize engine RPC client for the execution client under test."""

0 commit comments

Comments
 (0)