Skip to content

Commit 675e950

Browse files
committed
Don't accept bytes message in pytest.{fail,xfail,skip}
It seems to have been added in pytest-dev#1439 to fix pytest-dev#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.
1 parent 0b532fd commit 675e950

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

changelog/5615.removal.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
``pytest.fail``, ``pytest.xfail`` and ``pytest.skip`` no longer support bytes for the message argument.
2+
3+
This was supported for Python 2 where it was tempting to use ``"message"``
4+
instead of ``u"message"``.
5+
6+
Python 3 code is unlikely to pass ``bytes`` to these functions. If you do,
7+
please decode it to an ``str`` beforehand.

src/_pytest/outcomes.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import sys
66
from typing import Any
77
from typing import Optional
8-
from typing import Union
98

109
from packaging.version import Version
1110

@@ -18,19 +17,14 @@ class OutcomeException(BaseException):
1817
contain info about test and collection outcomes.
1918
"""
2019

21-
def __init__(
22-
self, msg: Optional[Union[str, bytes]] = None, pytrace: bool = True
23-
) -> None:
20+
def __init__(self, msg: Optional[str] = None, pytrace: bool = True) -> None:
2421
BaseException.__init__(self, msg)
2522
self.msg = msg
2623
self.pytrace = pytrace
2724

2825
def __repr__(self) -> str:
2926
if self.msg:
30-
val = self.msg
31-
if isinstance(val, bytes):
32-
val = val.decode("UTF-8", errors="replace")
33-
return val
27+
return self.msg
3428
return "<{} instance>".format(self.__class__.__name__)
3529

3630
__str__ = __repr__

0 commit comments

Comments
 (0)