Skip to content

pytest.HIDDEN_PARAM Causes Discovery Failure #25795

Description

@tobias-westerheide

Type: Bug

Using pytest.HIDDEN_PARAM in parametrized tests causes pytest discovery to fail with a ValueError in the VS Code Python extension's test discovery mechanism.

Steps to reproduce:

  1. Create a test file with a parametrized test using pytest.HIDDEN_PARAM:
import pytest

@pytest.mark.parametrize("setup", [pytest.param("setup", id=pytest.HIDDEN_PARAM)])
def test_main(setup) -> None:
    assert True
  1. Open the file in VS Code with the Python extension enabled
  2. Observe that pytest discovery fails

Diagnostic data

Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)

pytest test discovery error for workspace:  /tmp/test_pytest 
 Error Occurred, traceback: Traceback (most recent call last):
  File "/home/tobi/.vscode-server/extensions/ms-python.python-2026.0.0/python_files/vscode_pytest/__init__.py", line 428, in pytest_sessionfinish
    session_node: TestNode | None = build_test_tree(session)
                                    ~~~~~~~~~~~~~~~^^^^^^^^^
  File "/home/tobi/.vscode-server/extensions/ms-python.python-2026.0.0/python_files/vscode_pytest/__init__.py", line 691, in build_test_tree
    test_node = process_parameterized_test(
        test_case, test_node, function_nodes_dict, file_nodes_dict
    )
  File "/home/tobi/.vscode-server/extensions/ms-python.python-2026.0.0/python_files/vscode_pytest/__init__.py", line 617, in process_parameterized_test
    parent_part, parameterized_section = test_node["name"].split("[", 1)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: not enough values to unpack (expected 2, got 1)

Extension version: 2026.0.0
VS Code version: Code 1.109.3 (b6a47e94e326b5c209d118cf0f994d6065585705, 2026-02-12T17:54:48.470Z)
OS version: Windows_NT x64 10.0.26200
Modes:
Remote OS version: Linux x64 5.15.153.1-microsoft-standard-WSL2
Remote OS version: Linux x64 5.15.153.1-microsoft-standard-WSL2
Remote OS version: Linux x64 5.15.153.1-microsoft-standard-WSL2

  • Python version (& distribution if applicable, e.g. Anaconda): 3.11.11
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
  • Value of the python.languageServer setting: Default
User Settings


languageServer: "Pylance"

testing
• pytestArgs: "<placeholder>"
• pytestEnabled: true
• unittestArgs: "<placeholder>"

experiments
• optInto: ["pythonTestAdapter"]

Installed Extensions
Extension Name Extension Id Version
ansible red 26.1.3
auto-commit-msg Mic 0.27.2
autodocstring njp 0.6.1
change-case wma 1.0.0
code-spell-checker str 4.5.6
color-highlight nau 2.8.0
copilot-chat Git 0.37.6
debugpy ms- 2025.18.0
direnv mkh 0.17.0
djlint mon 2025.11.0
EditorConfig Edi 0.18.1
even-better-toml tam 0.21.2
gitignore cod 0.10.0
gitlab-workflow Git 6.69.3
gitlens eam 17.10.0
gitlink qez 1.2.6
go gol 0.52.2
isort ms- 2025.0.0
jinjahtml sam 0.20.0
js-debug ms- 1.105.0
jupyter ms- 2025.9.1
jupyter-renderers ms- 1.3.0
live-server ms- 0.4.17
markdown-all-in-one yzh 3.6.3
markdown-pdf yza 1.5.0
markdowntable Tak 0.13.0
marp-vscode mar 3.3.0
mypy-type-checker ms- 2025.2.0
oxc-vscode oxc 1.45.0
pdminterpreter Kal 0.0.5
plantuml jeb 2.18.1
prettier-vscode esb 12.3.0
python ms- 2026.0.0
ruff cha 2026.36.0
shellcheck tim 0.38.6
tfsec tfs 1.11.0
unique-window-colors stu 1.0.51
vscode-containers ms- 2.4.1
vscode-conventional-commits viv 1.27.0
vscode-coverage-gutters rya 2.14.0
vscode-django bat 1.15.0
vscode-js-profile-table ms- 1.0.10
vscode-jupyter-cell-tags ms- 0.1.9
vscode-jupyter-slideshow ms- 0.1.6
vscode-opentofu ope 0.6.0
vscode-pylance ms- 2025.10.4
vscode-python-envs ms- 1.16.0
vscode-stylelint sty 2.0.2
vscode-wakatime Wak 25.5.1
vscode-yaml red 1.19.1
vsliveshare ms- 1.0.5959
System Info
Item Value
CPUs Intel(R) Core(TM) Ultra 7 165U (14 x 2688)
GPU Status 2d_canvas: enabled
GPU0: VENDOR= 0x8086, DEVICE=0x7d45 [Intel(R) Graphics], DRIVER_VENDOR=Intel, DRIVER_VERSION=32.0.101.7026 ACTIVE
GPU1: VENDOR= 0x1414, DEVICE=0x008c [Microsoft Basic Render Driver], DRIVER_VERSION=10.0.26100.7309
Machine model name:
Machine model version:
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
trees_in_viz: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) undefined
Memory (System) 63.46GB (35.34GB free)
Process Argv --folder-uri=vscode-remote://wsl+Ubuntu-24.04/home/tobi/projects/gitlab.energiekoppler.com/ek/software/ee-redispatch --remote=wsl+Ubuntu-24.04
Screen Reader yes
VM 0%
Item Value
Remote WSL: Ubuntu-24.04
OS Linux x64 5.15.153.1-microsoft-standard-WSL2
CPUs Intel(R) Core(TM) Ultra 7 165U (14 x 0)
Memory (System) 31.08GB (18.75GB free)
VM 0%
Item Value
Remote WSL: Ubuntu-24.04
OS Linux x64 5.15.153.1-microsoft-standard-WSL2
CPUs Intel(R) Core(TM) Ultra 7 165U (14 x 0)
Memory (System) 31.08GB (18.75GB free)
VM 0%
Item Value
Remote WSL: Ubuntu-24.04
OS Linux x64 5.15.153.1-microsoft-standard-WSL2
CPUs Intel(R) Core(TM) Ultra 7 165U (14 x 0)
Memory (System) 31.08GB (18.83GB free)
VM 0%

Extended Info

Root Cause

The issue is in the process_parameterized_test function at line 617 of vscode_pytest/__init__.py:

parent_part, parameterized_section = test_node["name"].split("[", 1)

This code assumes that all parametrized tests have a [ character in their name (e.g., test_main[setup]). However, when using pytest.HIDDEN_PARAM, pytest intentionally omits the parameter brackets from the test ID, resulting in just test_main.

The .split("[", 1) call then returns a list with only one element (the test name without brackets), but the code tries to unpack it into two variables, causing the ValueError.

Suggested Fix

The process_parameterized_test function should check if the test name contains parameters before attempting to split:

if "[" in test_node["name"]:
    parent_part, parameterized_section = test_node["name"].split("[", 1)
    # Process parameterized test
else:
    # Handle test without visible parameters (e.g., HIDDEN_PARAM)
    parent_part = test_node["name"]
    # Treat as non-parameterized or handle appropriately

Additional Context

  • pytest.HIDDEN_PARAM is a documented pytest feature for hiding parameter values from test IDs
  • This is particularly useful for fixture setup that shouldn't be visible in test names
  • Command-line pytest handles this correctly; only VS Code discovery fails
  • Extension logs show collected 1 item before the error, suggesting pytest itself collected the test successfully

Workaround

Remove the use of pytest.HIDDEN_PARAM and use a regular string ID instead:

@pytest.mark.parametrize("setup", [pytest.param("setup", id="setup")])
def test_main(setup) -> None:
    assert True

However, this defeats the purpose of HIDDEN_PARAM and creates visible parameter IDs.

References

Activity

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

Metadata

Metadata

Labels

area-testingbugIssue identified by VS Code Team member as probable bugconfirmation pendingThe issue needs to be confirmed through a maintainer reproducing the bug.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions