{"id":"9e8a88e10b26884f","repo":"pytest-dev/pytest","slug":"expected-string-as-msg-parameter-got-in","errorCode":null,"errorMessage":"{} expected string as 'msg' parameter, got '{}' instead.\nPerhaps you meant to use a mark?","messagePattern":"(.+?) expected string as 'msg' parameter, got '(.+?)' instead\\.\nPerhaps you meant to use a mark\\?","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/_pytest/outcomes.py","lineNumber":23,"sourceCode":"\nimport importlib\nimport sys\nfrom typing import Any\nfrom typing import ClassVar\nfrom typing import NoReturn\n\n\nclass OutcomeException(BaseException):\n    \"\"\"OutcomeException and its subclass instances indicate and contain info\n    about test and collection outcomes.\"\"\"\n\n    def __init__(self, msg: str | None = None, pytrace: bool = True) -> None:\n        if msg is not None and not isinstance(msg, str):\n            error_msg = (  # type: ignore[unreachable]\n                \"{} expected string as 'msg' parameter, got '{}' instead.\\n\"\n                \"Perhaps you meant to use a mark?\"\n            )\n            raise TypeError(error_msg.format(type(self).__name__, type(msg).__name__))\n        super().__init__(msg)\n        self.msg = msg\n        self.pytrace = pytrace\n\n    def __repr__(self) -> str:\n        if self.msg is not None:\n            return self.msg\n        return f\"<{self.__class__.__name__} instance>\"\n\n    __str__ = __repr__\n\n\nTEST_OUTCOME = (OutcomeException, Exception)\n\n\nclass Skipped(OutcomeException):\n    # XXX hackish: on 3k we fake to live in the builtins\n    # in order to have Skipped exception printing shorter/nicer","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/pytest-dev/pytest/blob/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/outcomes.py#L5-L41","documentation":"OutcomeException.__init__ (base of Skipped/Failed/XFailed) requires msg to be a str or None. Passing any other type raises TypeError with a hint 'Perhaps you meant to use a mark?' because the common cause is calling pytest.skip/xfail/fail with a mark object or non-string reason.","triggerScenarios":"pytest.skip(some_object), pytest.fail(exception_instance), or pytest.xfail(reason) where reason is not a string. Also triggered by raising Skipped/Failed directly with a non-str arg.","commonSituations":"Calling pytest.skip(SomeException) intending to re-raise; passing a marker decorator where a reason string is expected; mixing up pytest.mark.skip with pytest.skip.","solutions":["Pass a string reason: pytest.skip('reason text')","If you meant a marker, use the decorator: @pytest.mark.skip(reason='...')","Convert the object to a string first: pytest.skip(str(obj))"],"exampleFix":"// before\npytest.skip(some_exception)\n// after\npytest.skip(str(some_exception))","handlingStrategy":"type-guard","validationCode":"def safe_skip(reason):\n    if reason is not None and not isinstance(reason, str):\n        reason = str(reason)\n    import pytest; pytest.skip(reason)","typeGuard":"def is_str_or_none(msg) -> bool:\n    return msg is None or isinstance(msg, str)","tryCatchPattern":null,"preventionTips":["Always pass a string reason to pytest.skip/fail/xfail","For decorator behavior use @pytest.mark.skip / @pytest.mark.xfail, not the function form"],"tags":["outcomes","skip","xfail","pytest","type-check"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}