diff --git a/tests/qos/conftest.py b/tests/qos/conftest.py index 9c22799fe4d..e5abfa47a55 100644 --- a/tests/qos/conftest.py +++ b/tests/qos/conftest.py @@ -175,6 +175,49 @@ def skip_lossy_buffer_only(is_lossy_only_pool): pytest.skip("Skip test for lossy only pool") +# Global variable to track fixture failures per parameter set for TestQosSai +_fixture_failures = {} + + +def pytest_sessionstart(session): + """Clear fixture failure tracking to prevent stale state in pytest-xdist workers.""" + _fixture_failures.clear() + + +def pytest_runtest_makereport(item, call): + """Record fixture failures during setup to skip subsequent tests in the same parameter set.""" + if not (hasattr(item, 'cls') and item.cls and item.cls.__name__ == 'TestQosSai'): + return + + if call.when == "setup" and call.excinfo is not None: + test_name = item.name + if '[' in test_name: + param_set = test_name.split('[')[1].rstrip(']') + else: + param_set = 'default' + + _fixture_failures[param_set] = True + + +def pytest_runtest_setup(item): + """Skip tests if fixtures failed for this parameter set.""" + if not (hasattr(item, 'cls') and item.cls and item.cls.__name__ == 'TestQosSai'): + return + + # Don't skip seed tests - let them fail naturally to show the root cause + if 'fixture_seed' in item.keywords: + return + + test_name = item.name + if '[' in test_name: + param_set = test_name.split('[')[1].rstrip(']') + else: + param_set = 'default' + + if param_set in _fixture_failures: + pytest.skip(f"Skipping because fixtures failed for parameter set [{param_set}]") + + @pytest.fixture(scope="module", autouse=True) def enable_dscp_remapping_on_dualtor_flag(request, duthost): """ diff --git a/tests/qos/test_qos_sai.py b/tests/qos/test_qos_sai.py index 4af6f184f85..c35dc3c1d5e 100644 --- a/tests/qos/test_qos_sai.py +++ b/tests/qos/test_qos_sai.py @@ -413,6 +413,7 @@ def check_and_set_ecn_status(self, duthost, qosConfig, expected_status='on'): return ecn_status + @pytest.mark.fixture_seed def testParameter( self, duthosts, get_src_dst_asic_and_duts, dutConfig, dutQosConfig, ingressLosslessProfile, ingressLossyProfile, egressLosslessProfile, dualtor_ports_for_duts