Skip to content

fix(pytest): support parameterized tests with unbracketed names (e.g., pytest.HIDDEN_PARAM) - #26233

Open
MOHAMMED WASIM KHAN (wasim-builds) wants to merge 4 commits into
microsoft:mainfrom
wasim-builds:fix-25795-pytest-hidden-param
Open

MOHAMMED WASIM KHAN (wasim-builds) wants to merge 4 commits into
microsoft:mainfrom
wasim-builds:fix-25795-pytest-hidden-param

Conversation

@wasim-builds

Copy link
Copy Markdown

Summary

Fixes #25795

When a test is parameterized using pytest.HIDDEN_PARAM (e.g. @pytest.mark.parametrize('setup', [pytest.param('setup', id=pytest.HIDDEN_PARAM)])), pytest does not append a bracketed parameter identifier [...] to the test item name. During test discovery, vscode_pytest.process_parameterized_test attempted test_node['name'].split('[', 1), raising:
ValueError: not enough values to unpack (expected 2, got 1)
and failing test discovery.

Changes

  1. In python_files/vscode_pytest/__init__.py:
    • Updated is_parameterized check in build_test_tree to verify '[' in test_node['name'] in addition to hasattr(test_case, 'callspec').
    • In process_parameterized_test, added a guard returning test_node if '[' not in test_node['name'].
    • Updated file node parenting in build_test_tree to handle tests where not is_parameterized.
  2. Added unit test in python_files/tests/pytestadapter/test_utils.py verifying that tests using pytest.HIDDEN_PARAM discover successfully and build the expected test tree without errors.

Verification

  • Ran python3 -m pytest python_files/tests/pytestadapter/test_utils.py (all 4 passed).

Copilot AI balanced review requested due to automatic review settings October 17, 2026 12:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pytest.HIDDEN_PARAM Causes Discovery Failure

2 participants