-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
TST replace assert_raises with the pytest.raises context manager in dummy module #19372
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
TST replace assert_raises with the pytest.raises context manager in dummy module #19372
Conversation
#DataUmbrella sprint |
sklearn/tests/test_dummy.py
Outdated
|
||
est = DummyRegressor(strategy="quantile", quantile='abc') | ||
assert_raises(TypeError, est.fit, X, y) | ||
with pytest.raises(ValueError): |
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.
with pytest.raises(ValueError): | |
with pytest.raises(TypeError): |
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.
Optionally, the whole test could be parameterizes as:
@pytest.mark.parametrize(
"quantile, error",
[
("default", ValueError),
(None, ValueError),
# TODO: Fill in the futher cases here
],
)
def test_quantile_invalid(quantile, error):
X = [[0]] * 5 # ignored
y = [0] * 5 # ignored
if quantile == "default":
est = DummyRegressor(strategy="quantile")
else:
est = DummyRegressor(strategy="quantile", quantile=quantile)
with pytest.raises(ValueError):
est.fit(X, y)
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.
I am not sure parametrization helps with readability in this case.
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.
LGTM. @icky254 Thank you for your contribution.
Thanks @icky254 Good to be merged. |
Reference Issues/PRs
Towards #14216
What does this implement/fix? Explain your changes.
Replaced assert_raises with the pytest context manager.
Any other comments?
Pair programming partner @marenwestermann