code: add ExceptionInfo.from_exception
The old-style `sys.exc_info()` triplet is redundant nowadays with `(type(exc), exc, exc.__traceback__)`, and is beginning to get soft-deprecated in Python 3.12. Add a nicer API to ExceptionInfo which takes just the exc instead of the triplet. There are already a few internal uses which benefit.
This commit is contained in:
@@ -53,6 +53,20 @@ def test_excinfo_from_exc_info_simple() -> None:
|
||||
assert info.type == ValueError
|
||||
|
||||
|
||||
def test_excinfo_from_exception_simple() -> None:
|
||||
try:
|
||||
raise ValueError
|
||||
except ValueError as e:
|
||||
assert e.__traceback__ is not None
|
||||
info = _pytest._code.ExceptionInfo.from_exception(e)
|
||||
assert info.type == ValueError
|
||||
|
||||
|
||||
def test_excinfo_from_exception_missing_traceback_assertion() -> None:
|
||||
with pytest.raises(AssertionError, match=r"must have.*__traceback__"):
|
||||
_pytest._code.ExceptionInfo.from_exception(ValueError())
|
||||
|
||||
|
||||
def test_excinfo_getstatement():
|
||||
def g():
|
||||
raise ValueError
|
||||
|
||||
Reference in New Issue
Block a user