-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add exception to value alias on ExceptionInfo #5541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
imho this should also issue a warning so users can fix their code up |
@RonnyPfannschmidt totally agree, what warning should it be? Deprecation warning feels fundamentally wrong here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @graingert!
See my suggestion about which warning and message to use.
Please target features
and add a CHANGELOG entry. 👍
cfa1cf3
to
127de96
Compare
For easier compatibility with unittest pytest-dev/unittest2pytest#36 Co-Authored-By: Bruno Oliveira <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@nicoddemus this should also apply to pytest.warns |
Co-Authored-By: Bruno Oliveira <[email protected]>
@nicoddemus eg aliases for all these: https://github.com/python/cpython/blob/3.7/Lib/unittest/case.py#L248-L261 |
Not sure if all of those, but |
@graingert still want to add the aliases for |
looking at it now |
@nicoddemus it's actually a bit of a pain as it would involve chainging how WarningsChecker works, eg it doesn't actually store the first matching warning anywhere |
@nicoddemus looks a bit like graingert@4a2ced9 |
I see. Well I think that's fine if indeed we want to add those aliases. 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @graingert for the follow up! Please take a look at my comments when you have the chance. 👍
@@ -186,28 +186,33 @@ def __exit__(self, *exc_info): | |||
__tracebackhide__ = True | |||
|
|||
# only check if we're not currently handling an exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a test for the warning
attribute to avoid regressions.
@@ -0,0 +1 @@ | |||
Add ``.exception`` attribute as an alias for ``.value`` to facilitate porting tests written using unittest. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be updated to mention the warning
attribute of pytest.warns
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh this should also be 5541.improvement.rst
now.
if issubclass(r.category, self.expected_warning) and ( | ||
self.match_expr is None or re.search(self.match_expr, str(r.message)) | ||
): | ||
self.warning = r.message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These attributes should be initialized with None
in __init__
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we should add a quick example to the docs to warnings.rst
. 👍
@graingert gentle ping |
Looks like this needs a rebase etc |
Indeed, also please see my comments. 👍 |
@property | ||
def exception(self): | ||
""" | ||
an alias to '.value' to facilitate porting porting tests written using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an alias to '.value' to facilitate porting porting tests written using | |
an alias to '.value' to facilitate porting tests written using |
This comment has been minimized.
This comment has been minimized.
TBH I'm not sure this is worthwhile doing anymore... perhaps it is better to improve unittest2pytest to deal with this automatically, and mention it more prominently in the docs? |
(I've changed the base on my own now). |
I agree with @nicoddemus; let's close this. |
For easier compatibility with unittest pytest-dev/unittest2pytest#36