Skip to content

Commit 127de96

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 <nicoddemus@gmail.com>
1 parent 4f9bf02 commit 127de96

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,16 @@ def type(self):
422422
def value(self):
423423
"""the exception value"""
424424
return self._excinfo[1]
425+
426+
@property
427+
def exception(self):
428+
msg = (
429+
"The '.exception' attribute is an alias to facilitate porting "
430+
"tests written using unittest.\n"
431+
"Prefer '.value' in new code."
432+
)
433+
warnings.warn(PytestWarning(msg), stacklevel=2)
434+
return self.value
425435

426436
@property
427437
def tb(self):

0 commit comments

Comments
 (0)