{"id":"4394c803b199e3b7","repo":"pytest-dev/pytest","slug":"pytest-param-cannot-add-pytest-mark-usefixtures-s","errorCode":null,"errorMessage":"pytest.param cannot add pytest.mark.usefixtures; see https://docs.pytest.org/en/stable/reference/reference.html#pytest-param","messagePattern":"pytest\\.param cannot add pytest\\.mark\\.usefixtures; see https://docs\\.pytest\\.org/en/stable/reference/reference\\.html#pytest-param","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/_pytest/mark/structures.py","lineNumber":127,"sourceCode":"    \"\"\"\n\n    values: Sequence[object | NotSetType]\n    marks: Collection[MarkDecorator | Mark]\n    id: str | _HiddenParam | None\n\n    @classmethod\n    def param(\n        cls,\n        *values: object,\n        marks: MarkDecorator | Collection[MarkDecorator | Mark] = (),\n        id: str | _HiddenParam | None = None,\n    ) -> ParameterSet:\n        if isinstance(marks, MarkDecorator):\n            marks = (marks,)\n        else:\n            assert isinstance(marks, collections.abc.Collection)\n        if any(i.name == \"usefixtures\" for i in marks):\n            raise ValueError(\n                \"pytest.param cannot add pytest.mark.usefixtures; see \"\n                \"https://docs.pytest.org/en/stable/reference/reference.html#pytest-param\"\n            )\n\n        if id is not None:\n            if not isinstance(id, str) and id is not HIDDEN_PARAM:\n                raise TypeError(\n                    \"Expected id to be a string or a `pytest.HIDDEN_PARAM` sentinel, \"\n                    f\"got {type(id)}: {id!r}\",\n                )\n        return cls(values, marks, id)\n\n    @classmethod\n    def extract_from(\n        cls,\n        parameterset: ParameterSet | Sequence[object] | object,\n        force_tuple: bool = False,\n    ) -> ParameterSet:","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/pytest-dev/pytest/blob/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/mark/structures.py#L109-L145","documentation":"`pytest.param(...)` explicitly forbids attaching `pytest.mark.usefixtures` via its `marks=` argument — usefixtures may only be applied to the test function itself. `ParameterSet.param` scans the provided marks and raises ValueError if any has `name == 'usefixtures'`. This is a deliberate API restriction.","triggerScenarios":"`pytest.param(1, 2, marks=pytest.mark.usefixtures('db'))` inside a parametrize values list.","commonSituations":"Trying to make only some parameter combinations use a fixture; copy-pasting a usefixtures mark into parametrize.","solutions":["Apply `@pytest.mark.usefixtures('db')` to the whole test function instead of to individual params.","If only some params need the fixture, split into two test functions or parametrize the fixture itself with `indirect=True`.","Use `params=` of the fixture to vary behavior instead of usefixtures on params."],"exampleFix":"# before\n@pytest.mark.parametrize('x', [pytest.param(1, marks=pytest.mark.usefixtures('db'))])\ndef test_x(x): ...\n# after\n@pytest.mark.usefixtures('db')\n@pytest.mark.parametrize('x', [1])\ndef test_x(x): ...","handlingStrategy":"validation","validationCode":"def has_no_usefixtures(marks) -> bool:\n    return all(getattr(m, 'name', getattr(getattr(m, 'mark', None), 'name', None)) != 'usefixtures' for m in marks)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Apply `usefixtures` at the function/class level, never inside `pytest.param`.","Review `marks=[...]` lists for stray usefixtures entries."],"tags":["pytest","parametrize","usefixtures","api-restriction"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}