From 675e9507d80fc477d416d38781e6bccc8bb5c0c2 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Wed, 17 Jul 2019 10:33:10 +0300 Subject: [PATCH] Don't accept bytes message in pytest.{fail,xfail,skip} It seems to have been added in #1439 to fix #1178. This was only relevant for Python 2 where it was tempting to use str (== bytes) literals instead of unicode literals. In Python 3, it is unlikely that anyone passes bytes to these functions. --- changelog/5615.removal.rst | 7 +++++++ src/_pytest/outcomes.py | 10 ++-------- 2 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 changelog/5615.removal.rst diff --git a/changelog/5615.removal.rst b/changelog/5615.removal.rst new file mode 100644 index 00000000000..6dd9aec1de5 --- /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 df37312ba15..a5a4e655b0e 100644 --- a/src/_pytest/outcomes.py +++ b/src/_pytest/outcomes.py @@ -5,7 +5,6 @@ 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__