{"record":{"id":"656b5b06d365f9c7","repo":"pytest-dev/pytest","slug":"directory-argument-cannot-contain-selection-par","errorCode":null,"errorMessage":"directory argument cannot contain :: selection parts: {arg}","messagePattern":"directory argument cannot contain :: selection parts: (.+?)","errorType":"validation","errorClass":"UsageError","httpStatus":null,"severity":"error","filePath":"src/_pytest/main.py","lineNumber":1180,"sourceCode":"        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))\n    if parts and fspath.is_dir():\n        msg = (\n            \"package argument cannot contain :: selection parts: {arg}\"\n            if as_pypath\n            else \"directory argument cannot contain :: selection parts: {arg}\"\n        )\n        raise UsageError(msg.format(arg=arg))\n    return CollectionArgument(\n        path=fspath,\n        parts=parts,\n        parametrization=parametrization,\n        module_name=module_name,\n        original_index=arg_index,\n    )\n\n\ndef is_collection_argument_subsumed_by(\n    arg: CollectionArgument, by: CollectionArgument\n) -> bool:\n    \"\"\"Check if `arg` is subsumed (contained) by `by`.\"\"\"\n    # First check path subsumption.\n    if by.path != arg.path:\n        # `by` subsumes `arg` if `by` is a parent directory of `arg` and has no\n        # parts (collects everything in that directory).\n        if not by.parts:","sourceCodeStart":1162,"sourceCodeEnd":1198,"githubUrl":"https://github.com/pytest-dev/pytest/blob/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/main.py#L1162-L1198","documentation":"The non-pyargs companion at main.py:1180 raises 'directory argument cannot contain :: selection parts: {arg}' when a plain directory argument (not --pyargs) contains '::'. '::' selects within a file/module; applying it to a directory is meaningless, so pytest rejects it.","triggerScenarios":"Running 'pytest tests/::TestClass' or 'pytest my_dir::test_func'; passing a directory with '::' selection parts.","commonSituations":"Confusing directory and file selection semantics; shell autocompletion appending '::'; copy-pasting a nodeid and replacing only the file portion with a directory.","solutions":["Target a specific file: 'pytest tests/test_x.py::TestClass'.","Drop the '::' parts to collect the whole directory."],"exampleFix":"// before\npytest tests/::TestClass\n// after\npytest tests/test_x.py::TestClass","handlingStrategy":"validation","validationCode":"from pathlib import Path\ndef validate_dir_arg(arg: str) -> str:\n    base = arg.split('::')[0]\n    if '::' in arg and Path(base).is_dir():\n        raise ValueError(f'directory {base!r} cannot take :: selection; target a file')\n    return arg","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Apply '::' selection only to files/modules, not directories.","Drop '::' to collect an entire directory.","Watch shell autocompletion appending '::'."],"tags":["pytest","collection","cli","selection","filesystem"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}