{"record":{"id":"e9234a1b6d17d5c3","repo":"pytest-dev/pytest","slug":"package-argument-cannot-contain-selection-parts","errorCode":null,"errorMessage":"package argument cannot contain :: selection parts: {arg}","messagePattern":"package 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":"main.py:1180 raises 'package argument cannot contain :: selection parts: {arg}' when --pyargs resolves to a package (directory) AND the argument also contains '::' selection parts. pytest does not support '::Class::method' selection inside a package-level --pyargs argument; you must target a module, not a package, for '::' selection.","triggerScenarios":"Running 'pytest --pyargs mypkg::SomeTest' where mypkg is a package directory; mixing a package name with class/method selection under --pyargs.","commonSituations":"Assuming '::' works the same on packages as on modules under --pyargs; misidentifying a package as a module.","solutions":["Point --pyargs at the module inside the package: 'pytest --pyargs mypkg.test_x::SomeTest'.","Drop the '::' parts if you want the whole package collected."],"exampleFix":"// before\npytest --pyargs mypkg::SomeTest  # mypkg is a package\n// after\npytest --pyargs mypkg.test_core::SomeTest","handlingStrategy":"validation","validationCode":"# If using --pyargs, target a module not a package when adding '::'\nimport importlib.util\ndef resolve_pyarg_target(arg: str) -> str:\n    mod = arg.split('::')[0]\n    spec = importlib.util.find_spec(mod)\n    if spec is None:\n        raise ValueError(f'{mod!r} not importable')\n    if spec.submodule_search_locations is not None and '::' in arg:\n        raise ValueError(f'package {mod!r} cannot take :: selection; target a module')\n    return arg","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Point --pyargs at a module (file) when using '::' selection.","Drop '::' to collect a whole package.","Confirm whether the dotted name is a package vs module."],"tags":["pytest","collection","pyargs","selection","cli"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}