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.
This commit is contained in:
parent
0b532fda76
commit
675e9507d8
|
@ -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.
|
|
@ -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__
|
||||
|
|
Loading…
Reference in New Issue