TST: Fix assert raises in sklearn/metrics/tests/#14715
TST: Fix assert raises in sklearn/metrics/tests/#14715rth merged 14 commits intoscikit-learn:masterfrom sameshl:tests_metrics
sklearn/metrics/tests/#14715Conversation
related to #14216
glemaitre
left a comment
There was a problem hiding this comment.
Same as other PRs: remove assert_raise_message.
sklearn/metrics/tests/test_common.py
Outdated
|
|
||
| # use context manager to supply custom error message | ||
| with assert_raises(AssertionError) as cm: | ||
| with pytest.raises(AssertionError) as cm: |
There was a problem hiding this comment.
This will not work as intended with pytest.
I think that we want something like this instead
with pytest.raises(AssertionError):
assert_array_equal(metric(y_true, y_pred), metric(y_pred, y_true))
raise ValueError("%s seems to be symmetric:" %name)There was a problem hiding this comment.
@glemaitre Thanks for pointing that out! Will make the required change.
sklearn/metrics/tests/test_common.py
Outdated
|
|
||
| # use context manager to supply custom error message | ||
| with assert_raises(AssertionError) as cm: | ||
| with pytest.raises(AssertionError) as cm: |
There was a problem hiding this comment.
This is the same issue than above. You need to raise a ValueError within the context manager.
| assert_raises_regex(ValueError, "Mean Squared Logarithmic Error cannot be " | ||
| "used when targets contain negative values.", | ||
| mean_squared_log_error, [1., -2., 3.], [1., 2., 3.]) | ||
| with pytest.raises(ValueError, match="Mean Squared Logarithmic Error " |
There was a problem hiding this comment.
You can move the message out of raises
glemaitre
left a comment
There was a problem hiding this comment.
Otherwise LGTM. We should open something to refactor these tests with parametrization.
|
@rth. I have made the required changes. You can have a look. |
|
@rth I have removed all except one instances of |
|
@thomasjpfan Can you have a look? |
sklearn/metrics/tests/sklearn/metrics/tests/
replaced
assert_raisesandassert_raises_regexwithpytest.raisescontext manager.related to #14216