Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Merged
merged 2 commits into from
Feb 7, 2021
Merged

TST replace assert_raises with the pytest.raises context manager in dummy module #19372

merged 2 commits into from
Feb 7, 2021

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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.