Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

isaacknjama
Copy link
Contributor

@isaacknjama isaacknjama commented Feb 6, 2021

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

@reshamas
Copy link
Member

reshamas commented Feb 6, 2021

#DataUmbrella sprint

@glemaitre glemaitre self-requested a review February 6, 2021 10:11

est = DummyRegressor(strategy="quantile", quantile='abc')
assert_raises(TypeError, est.fit, X, y)
with pytest.raises(ValueError):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
with pytest.raises(ValueError):
with pytest.raises(TypeError):

Copy link
Member

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)

Copy link
Member

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.

Copy link
Member

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

@glemaitre glemaitre changed the title replaced assert_raises with the pytest context manager TST replace assert_raises with the pytest.raises context manager in dummy module Feb 7, 2021
@glemaitre glemaitre merged commit bd67f12 into scikit-learn:main Feb 7, 2021
@glemaitre
Copy link
Member

Thanks @icky254 Good to be merged.

@isaacknjama isaacknjama deleted the pytest-raises-test_dummy branch February 7, 2021 11:14
@glemaitre glemaitre mentioned this pull request Apr 22, 2021
12 tasks
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