Skip to content

Commit 19cf929

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 d78025d commit 19cf929

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
@@ -566,6 +566,11 @@ def pytest_generate_tests(metafunc):
566566
xdist_group_mapper = getattr(metafunc.config, "xdist_group_mapper", None)
567567
param_list = []
568568

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

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

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

609620
metafunc.parametrize("test_case", param_list)

0 commit comments

Comments
 (0)