diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fce7978c4..59128a4fb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -44,15 +44,10 @@ repos: hooks: - id: rst-backticks - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.711 + rev: v0.720 hooks: - id: mypy - name: mypy (src) - files: ^src/ - args: [] - - id: mypy - name: mypy (testing) - files: ^testing/ + files: ^(src/|testing/) args: [] - repo: local hooks: 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/_code/code.py b/src/_pytest/_code/code.py index 30ab01235..7d72234e7 100644 --- a/src/_pytest/_code/code.py +++ b/src/_pytest/_code/code.py @@ -520,7 +520,9 @@ class ExceptionInfo(Generic[_E]): text = text[len(self._striptext) :] return text - def errisinstance(self, exc: "Type[BaseException]") -> bool: + def errisinstance( + self, exc: Union["Type[BaseException]", Tuple["Type[BaseException]", ...]] + ) -> bool: """ return True if the exception is an instance of exc """ return isinstance(self.value, exc) diff --git a/src/_pytest/outcomes.py b/src/_pytest/outcomes.py index aaf0b35fb..a5a4e655b 100644 --- a/src/_pytest/outcomes.py +++ b/src/_pytest/outcomes.py @@ -24,10 +24,7 @@ class OutcomeException(BaseException): 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__ diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 8e5a02292..82ed8b9cf 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -1164,7 +1164,7 @@ def _idval(val, argname, idx, idfn, item, config): return str(val) elif isinstance(val, REGEX_TYPE): return ascii_escaped(val.pattern) - elif enum is not None and isinstance(val, enum.Enum): + elif isinstance(val, enum.Enum): return str(val) elif (inspect.isclass(val) or inspect.isfunction(val)) and hasattr(val, "__name__"): return val.__name__ diff --git a/src/_pytest/runner.py b/src/_pytest/runner.py index edaee9725..8aae163c3 100644 --- a/src/_pytest/runner.py +++ b/src/_pytest/runner.py @@ -278,10 +278,7 @@ class SetupState: self._finalizers = {} def addfinalizer(self, finalizer, colitem): - """ attach a finalizer to the given colitem. - if colitem is None, this will add a finalizer that - is called at the end of teardown_all(). - """ + """ attach a finalizer to the given colitem. """ assert colitem and not isinstance(colitem, tuple) assert callable(finalizer) # assert colitem in self.stack # some unit tests don't setup stack :/ @@ -309,12 +306,9 @@ class SetupState: def _teardown_with_finalization(self, colitem): self._callfinalizers(colitem) - if hasattr(colitem, "teardown"): - colitem.teardown() + colitem.teardown() for colitem in self._finalizers: - assert ( - colitem is None or colitem in self.stack or isinstance(colitem, tuple) - ) + assert colitem in self.stack def teardown_all(self): while self.stack: