{"id":"b52bcb38cbf21b88","repo":"pytest-dev/pytest","slug":"path-cannot-contain-parametrization-arg","errorCode":null,"errorMessage":"path cannot contain [] parametrization: {arg}","messagePattern":"path cannot contain \\[\\] parametrization: (.+?)","errorType":"exception","errorClass":"UsageError","httpStatus":null,"severity":"error","filePath":"src/_pytest/main.py","lineNumber":1155,"sourceCode":"        \"pkg.tests.test_foo::TestClass::test_foo[a,b]\"\n\n    In which case we search sys.path for a matching module, and then return the *path* to the\n    found module, which may look like this:\n\n        CollectionArgument(\n            path=Path(\"/home/u/myvenv/lib/site-packages/pkg/tests/test_foo.py\"),\n            parts=[\"TestClass\", \"test_foo\"],\n            parametrization=\"[a,b]\",\n            module_name=\"pkg.tests.test_foo\",\n        )\n\n    If the path doesn't exist, raise UsageError.\n    If the path is a directory and selection parts are present, raise UsageError.\n    \"\"\"\n    base, squacket, rest = arg.partition(\"[\")\n    strpath, *parts = base.split(\"::\")\n    if squacket and not parts:\n        raise UsageError(f\"path cannot contain [] parametrization: {arg}\")\n    parametrization = f\"{squacket}{rest}\" if squacket else None\n    module_name = None\n    if as_pypath:\n        pyarg_strpath = search_pypath(\n            strpath, consider_namespace_packages=consider_namespace_packages\n        )\n        if pyarg_strpath is not None:\n            module_name = strpath\n            strpath = pyarg_strpath\n    fspath = invocation_path / strpath\n    fspath = absolutepath(fspath)\n    if not safe_exists(fspath):\n        msg = (\n            \"module or package not found: {arg} (missing __init__.py?)\"\n            if as_pypath\n            else \"file or directory not found: {arg}\"\n        )\n        raise UsageError(msg.format(arg=arg))","sourceCodeStart":1137,"sourceCodeEnd":1173,"githubUrl":"https://github.com/pytest-dev/pytest/blob/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/main.py#L1137-L1173","documentation":"Raised by `resolve_collection_argument` when a command-line path argument contains a `[...]` parametrization bracket but no `::` selection part before it. Parametrization IDs may only be appended to a concrete test node selection (`file::node`), never to a bare path.","triggerScenarios":"Running `pytest \"tests/test_foo.py[a-b]\"` (parametrization with no `::` test id), or `pytest \"tests[a]\"`. The partition finds a `[` but `parts` (from `::` split) is empty.","commonSituations":"Misremembering the selection syntax. Trying to run all parametrized cases of a file at once via brackets. Shell auto-completion producing an incomplete node id.","solutions":["Add the `::` selection before the brackets: `pytest \"tests/test_foo.py::test_case[a-b]\"`.","To run all cases of a test, omit the brackets: `pytest tests/test_foo.py::test_case`.","Quote the argument in the shell to avoid glob expansion of `[`."],"exampleFix":"// before\n$ pytest \"tests/test_foo.py[a-b]\"\n// after\n$ pytest \"tests/test_foo.py::test_case[a-b]\"","handlingStrategy":"validation","validationCode":"def validate_node_id(arg: str):\n    base, bracket, _ = arg.partition(\"[\")\n    parts = base.split(\"::\")\n    if bracket and len(parts) == 1:\n        raise ValueError(f\"path cannot contain [] parametrization without '::': {arg}\")\n    return arg","typeGuard":"def node_id_has_selection(arg: str) -> bool:\n    return \"::\" in arg.partition(\"[\")[0]","tryCatchPattern":null,"preventionTips":["Always include a '::test_id' before parametrization brackets.","Quote bracket arguments in the shell.","Drop brackets to run all cases of a test."],"tags":["pytest","collection","cli","parametrization","usageerror"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}