Skip to content

Commit 1ebc8f9

Browse files
graingertnicoddemus
andcommitted
Add exception to value alias on ExceptionInfo
For easier compatibility with unittest pytest-dev/unittest2pytest#36 Co-Authored-By: Bruno Oliveira <[email protected]>
1 parent 4f9bf02 commit 1ebc8f9

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

changelog/5541.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add '.exception' attribute as an alias for '.value' to facilitate porting tests written using unittest.

src/_pytest/_code/code.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,20 @@ def type(self):
422422
def value(self):
423423
"""the exception value"""
424424
return self._excinfo[1]
425+
426+
@property
427+
def exception(self):
428+
"""
429+
an alias to '.value' to facilitate porting porting tests written using
430+
unittest. Prefer '.value' in new code.
431+
"""
432+
msg = (
433+
"The '.exception' attribute is an alias to facilitate porting "
434+
"tests written using unittest.\n"
435+
"Prefer '.value' in new code."
436+
)
437+
warnings.warn(PytestWarning(msg), stacklevel=2)
438+
return self.value
425439

426440
@property
427441
def tb(self):

0 commit comments

Comments
 (0)