Skip to content

Commit c49dd35

Browse files
committed
refactor(consume): use fixture format detection for enginex parametrization
Replace function name check with fixture format detection to properly distinguish between engine and enginex simulators. Both use the same test function name but process different fixture formats: - Engine simulator: "blockchain_test_engine" → standard parametrization - EngineX simulator: "blockchain_test_engine_x" → enhanced parametrization with xdist group splitting and load balancing This provides more robust detection and avoids the design flaw of hardcoding test function names.
1 parent 6e7e28d commit c49dd35

File tree

1 file changed

+40
-29
lines changed

1 file changed

+40
-29
lines changed

src/pytest_plugins/consume/consume.py

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,11 @@ def pytest_generate_tests(metafunc):
567567
xdist_group_mapper = getattr(metafunc.config, "xdist_group_mapper", None)
568568
param_list = []
569569

570+
# Check if this is an enginex simulator (has enginex-specific enhancements)
571+
is_enginex_function = (
572+
hasattr(metafunc.config, "_supported_fixture_formats")
573+
and "blockchain_test_engine_x" in metafunc.config._supported_fixture_formats
574+
)
570575
for test_case in test_cases:
571576
# Check if _supported_fixture_formats is set, if not allow all formats
572577
supported_formats = getattr(metafunc.config, "_supported_fixture_formats", None)
@@ -575,36 +580,42 @@ def pytest_generate_tests(metafunc):
575580

576581
fork_markers = get_relative_fork_markers(test_case.fork, strict_mode=False)
577582

578-
# Determine xdist group name first
579-
if xdist_group_mapper and hasattr(test_case, "pre_hash") and test_case.pre_hash:
580-
# Use the mapper to get potentially split group name
581-
xdist_group_name = xdist_group_mapper.get_xdist_group_name(test_case)
582-
elif hasattr(test_case, "pre_hash") and test_case.pre_hash:
583-
# No mapper or not enginex, use pre_hash directly
584-
xdist_group_name = test_case.pre_hash
585-
else:
586-
# No pre_hash, use test ID
587-
xdist_group_name = test_case.id
588-
589-
# Create test ID showing the xdist group name for easier identification
583+
# Basic test ID and markers (used by all consume tests)
590584
test_id = test_case.id
591-
if hasattr(test_case, "pre_hash") and test_case.pre_hash:
592-
# Show first 8 chars of xdist group name (includes sub-group if split)
593-
group_display = xdist_group_name[:8] if len(xdist_group_name) > 8 else xdist_group_name
594-
# If it's a split group (contains ':'), show that clearly
595-
if ":" in xdist_group_name:
596-
# Extract sub-group number for display
597-
pre_hash_part, sub_group = xdist_group_name.split(":", 1)
598-
group_display = f"{pre_hash_part[:8]}:{sub_group}"
599-
test_id = f"{test_case.id}[{group_display}]"
600-
601-
param = pytest.param(
602-
test_case,
603-
id=test_id,
604-
marks=[getattr(pytest.mark, m) for m in fork_markers]
605-
+ [getattr(pytest.mark, test_case.format.format_name)]
606-
+ [pytest.mark.xdist_group(name=xdist_group_name)],
607-
)
585+
markers = [getattr(pytest.mark, m) for m in fork_markers] + [
586+
getattr(pytest.mark, test_case.format.format_name)
587+
]
588+
589+
# Apply enginex-specific enhancements only for enginex functions
590+
if is_enginex_function:
591+
# Determine xdist group name for enginex load balancing
592+
if xdist_group_mapper and hasattr(test_case, "pre_hash") and test_case.pre_hash:
593+
# Use the mapper to get potentially split group name
594+
xdist_group_name = xdist_group_mapper.get_xdist_group_name(test_case)
595+
elif hasattr(test_case, "pre_hash") and test_case.pre_hash:
596+
# No mapper or not enginex, use pre_hash directly
597+
xdist_group_name = test_case.pre_hash
598+
else:
599+
# No pre_hash, use test ID
600+
xdist_group_name = test_case.id
601+
602+
# Create enhanced test ID showing the xdist group name for easier identification
603+
if hasattr(test_case, "pre_hash") and test_case.pre_hash:
604+
# Show first 8 chars of xdist group name (includes sub-group if split)
605+
group_display = (
606+
xdist_group_name[:8] if len(xdist_group_name) > 8 else xdist_group_name
607+
)
608+
# If it's a split group (contains ':'), show that clearly
609+
if ":" in xdist_group_name:
610+
# Extract sub-group number for display
611+
pre_hash_part, sub_group = xdist_group_name.split(":", 1)
612+
group_display = f"{pre_hash_part[:8]}:{sub_group}"
613+
test_id = f"{test_case.id}[{group_display}]"
614+
615+
# Add xdist group marker for load balancing
616+
markers.append(pytest.mark.xdist_group(name=xdist_group_name))
617+
618+
param = pytest.param(test_case, id=test_id, marks=markers)
608619
param_list.append(param)
609620

610621
metafunc.parametrize("test_case", param_list)

0 commit comments

Comments
 (0)