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

[MRG] CLN Remove the use of assert_raises in utils/ #16337

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 11 commits into from
Feb 2, 2020

Conversation

Batalex
Copy link
Contributor

@Batalex Batalex commented Jan 31, 2020

Reference Issues/PRs

Related to #14216

What does this implement/fix? Explain your changes.

Replace occurences of assert_raises & assert_raises_regex in the following files:

  • sklearn/utils/tests/test_class_weight.py
  • sklearn/utils/tests/test_estimator_checks.py
  • sklearn/utils/tests/test_multiclass.py
  • sklearn/utils/tests/test_random.py
  • sklearn/utils/tests/test_sparsefuncs.py
  • sklearn/utils/tests/test_testing.py
  • sklearn/utils/tests/test_utils.py
  • sklearn/utils/tests/test_validation.py

Any other comments?

  1. Should we replace assert_warns with pytest.warns context manager?
  2. It seems that assert_raises is also used outside test files (namely, sklearn/utils/_testing.py and
    sklearn/utils/estimator_checks.py for simple checks. Is that normal? Does it not risk to produce errors with the python -O flag?

Edit: test_estimator_checks.py has been reverted to its prior state because it should run even without pytest.

@jeremiedbb
Copy link
Member

Should we replace assert_warns with pytest.warns context manager?

+1

It seems that assert_raises is also used outside test files (namely, sklearn/utils/_testing.py and
sklearn/utils/estimator_checks.py for simple checks. Is that normal? Does it not risk to produce errors with the python -O flag?

These are helpers, only used in the tests

assert_raises(TypeError, incr_mean_variance_axis, X_lil, axis,
last_mean, last_var, last_n)

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.

So we ran this test twice on master ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, it could have been on purpose if the function was mutating an argument but that is not the case here :)

@thomasjpfan thomasjpfan changed the title [WIP] CLN Remove the use of assert_raises in utils/ [MRG] CLN Remove the use of assert_raises in utils/ Feb 1, 2020
@Batalex
Copy link
Contributor Author

Batalex commented Feb 2, 2020

Please note that there still are some references to assert_raises and assert_raises_message in test_testing.py. They should be kept as long as these functions are used elsewhere

Copy link
Member

@rth rth left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @Batalex !

@rth
Copy link
Member

rth commented Feb 2, 2020

Although unfortunately we will have to revert changes in sklearn/utils/tests/test_estimator_checks.py because it needs to run without pytest installed (hence the CI failure) to check that check_estimator function works without pytest.

Copy link
Member

@rth rth left a comment

Choose a reason for hiding this comment

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

LGTM, assuming CI passes. Thanks @Batalex !

@agramfort agramfort merged commit 418e0d5 into scikit-learn:master Feb 2, 2020
@agramfort
Copy link
Member

thx @Batalex

@Batalex Batalex deleted the test/pytest-utils branch February 2, 2020 14:19
thomasjpfan pushed a commit to thomasjpfan/scikit-learn that referenced this pull request Feb 22, 2020
* CLN use pytest raises ctxt manager for class weights & estimators [skip ci]

* CLN use pytest raises ctxt manager for multiclass test

* CLN use pytest warns in estimator checks test

* CLN use pytest raises ctxt manager for random test

* CLN use pytest raises ctxt manager for sparsefuncs test

* CLN use pytest raises ctxt manager for testing utils tests

* CLN use pytest raises ctxt manager for utils tests

* CLN use pytest raises ctxt manager for validation tests

* revert test_estimator_check.py to upstream master
panpiort8 pushed a commit to panpiort8/scikit-learn that referenced this pull request Mar 3, 2020
* CLN use pytest raises ctxt manager for class weights & estimators [skip ci]

* CLN use pytest raises ctxt manager for multiclass test

* CLN use pytest warns in estimator checks test

* CLN use pytest raises ctxt manager for random test

* CLN use pytest raises ctxt manager for sparsefuncs test

* CLN use pytest raises ctxt manager for testing utils tests

* CLN use pytest raises ctxt manager for utils tests

* CLN use pytest raises ctxt manager for validation tests

* revert test_estimator_check.py to upstream master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.