Skip to content

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

Closed
wants to merge 3 commits into from

Conversation

graingert
Copy link
Member

@graingert graingert commented Jul 3, 2019

For easier compatibility with unittest pytest-dev/unittest2pytest#36

@RonnyPfannschmidt
Copy link
Member

imho this should also issue a warning so users can fix their code up

@graingert
Copy link
Member Author

@RonnyPfannschmidt totally agree, what warning should it be? Deprecation warning feels fundamentally wrong here

Copy link
Member

@nicoddemus nicoddemus left a 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. 👍

@graingert graingert changed the base branch from master to features July 3, 2019 10:52
@graingert graingert force-pushed the patch-2 branch 2 times, most recently from cfa1cf3 to 127de96 Compare July 3, 2019 10:56
For easier compatibility with unittest pytest-dev/unittest2pytest#36

Co-Authored-By: Bruno Oliveira <[email protected]>
Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@graingert
Copy link
Member Author

@nicoddemus this should also apply to pytest.warns

@graingert
Copy link
Member Author

@nicoddemus
Copy link
Member

@nicoddemus eg aliases for all these:

Not sure if all of those, but warning <=> expected_warning I think so. 👍

@nicoddemus
Copy link
Member

@graingert still want to add the aliases for pytest.warns?

@graingert
Copy link
Member Author

looking at it now

@graingert
Copy link
Member Author

@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

@graingert
Copy link
Member Author

@nicoddemus looks a bit like graingert@4a2ced9

@nicoddemus
Copy link
Member

I see. Well I think that's fine if indeed we want to add those aliases. 👍

Copy link
Member

@nicoddemus nicoddemus left a 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
Copy link
Member

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.
Copy link
Member

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

Copy link
Member

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
Copy link
Member

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__

Copy link
Member

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. 👍

@pytest-dev pytest-dev deleted a comment from codecov bot Nov 5, 2019
@blueyed
Copy link
Contributor

blueyed commented Nov 5, 2019

@graingert gentle ping

@graingert
Copy link
Member Author

Looks like this needs a rebase etc

@nicoddemus
Copy link
Member

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
an alias to '.value' to facilitate porting porting tests written using
an alias to '.value' to facilitate porting tests written using

@bluetech

This comment has been minimized.

@nicoddemus
Copy link
Member

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?

@bluetech bluetech changed the base branch from features to master February 16, 2020 15:14
@bluetech
Copy link
Member

We've recently stopped using the features branch

(I've changed the base on my own now).

@bluetech
Copy link
Member

I agree with @nicoddemus; let's close this.

@bluetech bluetech closed this May 26, 2020
@graingert graingert deleted the patch-2 branch August 1, 2022 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants