Skip to content

Commit 7e7c965

Browse files
committed
use the formatted traceback if there's no exc_value
1 parent d2045ce commit 7e7c965

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/_pytest/unraisableexception.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@ def collect_unraisable() -> None:
7575
try:
7676
warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))
7777
except pytest.PytestUnraisableExceptionWarning as e:
78-
# exceptions have a better way to show the traceback, but
79-
# warnings do not, so hide the traceback from the msg and
80-
# set the cause so the traceback shows up in the right place
81-
e.args = (meta.cause_msg,)
82-
e.__cause__ = meta.exc_value
78+
if meta.exc_value is not None:
79+
# exceptions have a better way to show the traceback, but
80+
# warnings do not, so hide the traceback from the msg and
81+
# set the cause so the traceback shows up in the right place
82+
e.args = (meta.cause_msg,)
83+
e.__cause__ = meta.exc_value
8384
errors.append(e)
8485

8586
if len(errors) == 1:

0 commit comments

Comments
 (0)