Skip to content

Commit

Permalink
Add exception to value alias on ExceptionInfo
Browse files Browse the repository at this point in the history
For easier compatibility with unittest pytest-dev/unittest2pytest#36

Co-Authored-By: Bruno Oliveira <[email protected]>
  • Loading branch information
graingert and nicoddemus committed Jul 3, 2019
1 parent 4f9bf02 commit 127de96
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/5541.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add '.exception' attribute as an alias for '.value' to facilitate porting tests written using unittest.
10 changes: 10 additions & 0 deletions src/_pytest/_code/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,16 @@ def type(self):
def value(self):
"""the exception value"""
return self._excinfo[1]

@property
def exception(self):
msg = (
"The '.exception' attribute is an alias to facilitate porting "
"tests written using unittest.\n"
"Prefer '.value' in new code."
)
warnings.warn(PytestWarning(msg), stacklevel=2)
return self.value

@property
def tb(self):
Expand Down

0 comments on commit 127de96

Please sign in to comment.