diff --git a/changelog/5615.removal.rst b/changelog/5615.removal.rst new file mode 100644 index 000000000..6dd9aec1d --- /dev/null +++ b/changelog/5615.removal.rst @@ -0,0 +1,7 @@ +``pytest.fail``, ``pytest.xfail`` and ``pytest.skip`` no longer support bytes for the message argument. + +This was supported for Python 2 where it was tempting to use ``"message"`` +instead of ``u"message"``. + +Python 3 code is unlikely to pass ``bytes`` to these functions. If you do, +please decode it to an ``str`` beforehand. diff --git a/src/_pytest/outcomes.py b/src/_pytest/outcomes.py index df37312ba..a5a4e655b 100644 --- a/src/_pytest/outcomes.py +++ b/src/_pytest/outcomes.py @@ -5,7 +5,6 @@ as well as functions creating them import sys from typing import Any from typing import Optional -from typing import Union from packaging.version import Version @@ -18,19 +17,14 @@ class OutcomeException(BaseException): contain info about test and collection outcomes. """ - def __init__( - self, msg: Optional[Union[str, bytes]] = None, pytrace: bool = True - ) -> None: + def __init__(self, msg: Optional[str] = None, pytrace: bool = True) -> None: BaseException.__init__(self, msg) self.msg = msg self.pytrace = pytrace def __repr__(self) -> str: if self.msg: - val = self.msg - if isinstance(val, bytes): - val = val.decode("UTF-8", errors="replace") - return val + return self.msg return "<{} instance>".format(self.__class__.__name__) __str__ = __repr__