Skip to content

[MRG+2] Fix problematic caveat in ignore_warnings#11599

Merged
glemaitre merged 3 commits intoscikit-learn:masterfrom
lesteve:improve-ignore-warnings
Jul 17, 2018
Merged

[MRG+2] Fix problematic caveat in ignore_warnings#11599
glemaitre merged 3 commits intoscikit-learn:masterfrom
lesteve:improve-ignore-warnings

Conversation

@lesteve
Copy link
Copy Markdown
Member

@lesteve lesteve commented Jul 17, 2018

When the warning class is passed as a positional argument, the function is not called.

This is a slightly dangerous caveat of ignore_warnings in a test settings: basically the test is not run.

from sklearn.utils.testing import ignore_warnings

@ignore_warnings(UserWarning)
def test():
    1/0
❯ pytest /tmp/test.py
======================================================== test session starts ========================================================
platform linux -- Python 3.6.5, pytest-3.6.0, py-1.5.3, pluggy-0.6.0
rootdir: /tmp, inifile:
plugins: cov-2.5.1, hypothesis-3.56.0
collected 0 items                                                                                                                   

=================================================== no tests ran in 0.14 seconds ====================================================

@massich
Copy link
Copy Markdown
Contributor

massich commented Jul 17, 2018

Good! LGTM

I'll try to run the tests on my fork. to overcome the CIs bottle neck.

lesteve added 2 commits July 17, 2018 21:01
When the warning class is passed as a positional argument, the function is not called.
In a test settings this can mean that the test is not run.
The first argument is the test callable. Doing it like this cause the test
function to not be called
@lesteve lesteve force-pushed the improve-ignore-warnings branch from b168e9f to bc98f58 Compare July 17, 2018 19:22
@GaelVaroquaux GaelVaroquaux changed the title [MRG] Fix problematic caveat in ignore_warnings [MRG+1] Fix problematic caveat in ignore_warnings Jul 17, 2018
Copy link
Copy Markdown
Member

@GaelVaroquaux GaelVaroquaux left a comment

Choose a reason for hiding this comment

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

Great job!

+1 for merge, once CI are green.

@GaelVaroquaux GaelVaroquaux changed the title [MRG+1] Fix problematic caveat in ignore_warnings [MRG+2] Fix problematic caveat in ignore_warnings Jul 17, 2018
Copy link
Copy Markdown
Member

@TomDLT TomDLT left a comment

Choose a reason for hiding this comment

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

Good catch!

@glemaitre glemaitre merged commit e1dd0d8 into scikit-learn:master Jul 17, 2018
@lesteve lesteve deleted the improve-ignore-warnings branch July 17, 2018 21:17
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.

6 participants