-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Parameterize conditional raises #4679
Conversation
I'm -1 on putting this new name into |
Codecov Report
@@ Coverage Diff @@
## features #4679 +/- ##
===========================================
- Coverage 95.7% 95.7% -0.01%
===========================================
Files 111 111
Lines 24786 24798 +12
Branches 2469 2469
===========================================
+ Hits 23722 23732 +10
Misses 750 750
- Partials 314 316 +2
Continue to review full report at Codecov.
|
1 similar comment
Codecov Report
@@ Coverage Diff @@
## features #4679 +/- ##
===========================================
- Coverage 95.7% 95.7% -0.01%
===========================================
Files 111 111
Lines 24786 24798 +12
Branches 2469 2469
===========================================
+ Hits 23722 23732 +10
Misses 750 750
- Partials 314 316 +2
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## features #4679 +/- ##
===========================================
- Coverage 95.7% 95.7% -0.01%
===========================================
Files 111 111
Lines 24786 24798 +12
Branches 2469 2469
===========================================
+ Hits 23722 23732 +10
Misses 750 750
- Partials 314 316 +2
Continue to review full report at Codecov.
|
Thanks, @wimglenn! The argument for including a null context manager (
I believe it is worthwhile to be able to conditionally parameterize |
I was leaning against having this in pytest as well, but we do have to balance the cost of maintainability vs usability. From the maintainability point of view this is really trivial to implement, and may be eventually become an alias to For users which need the functionality, having it available in pytest is definitely a good thing. As much as it is simple to implement this yourself, is still nice to have it ready for use. The last point against adding this was the potential for misuse. The documentation should be very clear that the only use case for using So all in all I'm OK with this getting into the core. |
Btw many thanks @arel for your work on this. 👍 |
i consider this a great add - but i also want to ensure we document the intent and the limits correctly |
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 looks good, a small reference in the docs for raises and the note on the excinfo
usage should turn this into something we can safely merge
good work :)
def test_division(example_input, expectation): | ||
'''Test how much I know division.''' | ||
with expectation: | ||
assert (6 / example_input) is not None |
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 should have a warning here for the usage like
with expectation as excinfo: ....
``` - that excinfo will be None
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! I updated the sphinx documentation in 77dcac8 regarding execinfo
and also added a reference in pytest.raises
.
I'm aware of the use-cases, but still firmly against - it's adding a name that will be practically obsoleted by the end of this year. Beyond 2020+ that's just going to be another name hanging around which is a different way of doing the same thing. By the way, just because I'm curious - what is the |
Thanks. The |
@@ -0,0 +1 @@ | |||
A context manager ``does_not_raise`` is added to complement ``raises`` in parametrized tests with conditional raises. |
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.
@nicoddemus, before you let this PR get bike-shed completely, keep in mind the following things:
|
That is not a limitation in The problem with adding API surface area for a *I'm not suggesting to implement such features in this PR. Python 2 users having to install a contextlib backport to use the recipe from the docs is no big deal. #4324 is the right place to continue any discussion. |
personally i'm quite sad that we don't have this as utility for symmetry and better comprehension of test specifications the enhancement idea for adding a more comprehensible error descriptions would be a great add-on |
@arel I kind of lean towards your points, but given that we have strong 👎 from other maintainers, I feel we still have to reject the proposal. Sorry. |
This PR addresses issues #4324 and #1830, which documents how to use
pytest.raises
conditionally together withpytest.mark.parametrize
.Also, adopting the suggestion from @RonnyPfannschmidt #1830 (comment) and others, I added a context manager
pytest.does_not_raise
to make usage more friendly.Example:
Thanks! Let me know if I missed anything in the contribution guide.
Thanks for submitting a PR, your contribution is really appreciated!
Here's a quick checklist that should be present in PRs (you can delete this text from the final description, this is
just a guideline):
changelog
folder, with a name like<ISSUE NUMBER>.<TYPE>.rst
. See changelog/README.rst for details.master
branch for bug fixes, documentation updates and trivial changes.features
branch for new features and removals/deprecations.Unless your change is trivial or a small documentation fix (e.g., a typo or reword of a small section) please:
AUTHORS
in alphabetical order;