From 404f9434bd3c8199b000c0a257018ed3085c6fef Mon Sep 17 00:00:00 2001 From: Nikhil Hegde Date: Mon, 6 Jul 2026 21:33:08 +0000 Subject: [PATCH 1/2] [conditional_mark] Fix nodeid normalization so skips apply when rootdir floats up conditional_mark's rule keys are relative to the tests/ directory (e.g. "platform_tests/api"). To match them, pytest_collection_modifyitems normalizes each item.nodeid by stripping basename(rootpath)+"/" (added for pytest 9.0+ in PR #22944). That normalization is insufficient when pytest's rootdir is not the tests/ directory. When the test harness is invoked with a path argument that lives outside tests/ (for example `--inventory ../ansible/veos_vtb`, as run_tests.sh does), pytest 9.0 floats rootdir up to the sonic-mgmt checkout root. item.nodeid then carries a leading "tests/" segment ("tests/platform_tests/api/..."), while root_prefix is basename(checkout)+"/", which does not prefix it. The strip no-ops, the "tests/" survives, and every `nodeid.startswith()` comparison fails -> no conditional mark is ever applied (Found match: 0, skipped: 0). The practical effect is that all conditional skips/xfails silently stop firing in that invocation mode. For example on a virtual-switch (asic_type: vs) DUT the `platform_tests/api: skip if asic_type in ['vs']` rule no longer applies, so the platform-API tests run and error with "No module named 'sonic_platform'" instead of skipping ("Unsupported platform API"). Fix: after the existing basename(rootpath) strip, also strip a leading "tests/" so nodeids match the tests/-relative rule keys regardless of where pytest resolved rootdir. Verified on a virtual-switch testbed: platform_tests/api/test_watchdog.py goes from 8 errors to 8 skipped, platform_tests/api/test_psu.py to 14 skipped (all "Unsupported platform API"), and platform_tests/sfp/test_sfputil.py's `asic_type in ['vs']` xfail rule fires as expected. Signed-off-by: Nikhil Hegde --- tests/common/plugins/conditional_mark/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/common/plugins/conditional_mark/__init__.py b/tests/common/plugins/conditional_mark/__init__.py index ca37edd29d5..3be49df892c 100644 --- a/tests/common/plugins/conditional_mark/__init__.py +++ b/tests/common/plugins/conditional_mark/__init__.py @@ -711,12 +711,16 @@ def pytest_collection_modifyitems(session, config, items): json.dumps(basic_facts, indent=2))) dynamic_update_skip_reason = session.config.option.dynamic_update_skip_reason basic_facts['constants'] = MARK_CONDITIONS_CONSTANTS - # Normalize nodeids: strip root directory prefix if present (pytest 9.0+ includes it) + # Normalize nodeids to match the tests/-relative condition keys. rootdir may + # float above tests/ (e.g. --inventory ../ansible/veos_vtb), so strip both + # basename(rootpath) and a leading "tests/" or all conditional skips no-op. root_prefix = os.path.basename(str(session.config.rootpath)) + "/" for item in items: nodeid = item.nodeid if nodeid.startswith(root_prefix): nodeid = nodeid[len(root_prefix):] + if nodeid.startswith("tests/"): + nodeid = nodeid[len("tests/"):] all_matches = find_all_matches(nodeid, conditions, session, dynamic_update_skip_reason, basic_facts) if all_matches: From 68d19114952edf6203b42fa41f7e0daed8186cd1 Mon Sep 17 00:00:00 2001 From: Nikhil Hegde Date: Mon, 6 Jul 2026 23:50:54 +0000 Subject: [PATCH 2/2] ci: re-trigger pipeline (transient apt/dpkg lock flake dropped jq) Signed-off-by: Nikhil Hegde