Skip to content

[MRG + 1] Prevent nose from using docstring to name the tests in results#4250

Closed
raghavrv wants to merge 0 commit intoscikit-learn:masterfrom
raghavrv:travis_ignore_docstring
Closed

[MRG + 1] Prevent nose from using docstring to name the tests in results#4250
raghavrv wants to merge 0 commit intoscikit-learn:masterfrom
raghavrv:travis_ignore_docstring

Conversation

@raghavrv
Copy link
Copy Markdown
Member

ISSUE

When docstrings are added to test_* functions, nose uses them as headers when a particular test fails. This is not very convenient, compared to the function name and the passed arguments (in case of generators).

And also as pointed out in the link shared by Joel, test generators do not respect the generators docstring... Most generators use naming similar to check_*. Docstrings need not be removed in such cases.

Whether the generators need to be decorated by a method which sets its description is debatable.

FIX

  • Convert all docstring to comments
  • Decorate all test generators with a @test_describe('description') ( ? )

@amueller @ogrisel Please take a look

@raghavrv raghavrv force-pushed the travis_ignore_docstring branch 2 times, most recently from cd8808d to 5a07dde Compare February 15, 2015 18:50
@jnothman
Copy link
Copy Markdown
Member

This is interesting... For test generators, one is able to set test_function.description to override the docstring. However as here, you need the function to be copied (perhaps by partial) for each description to be correctly displayed. This could be done by a decorator of some kind, but isn't particularly friendly...

@GaelVaroquaux
Copy link
Copy Markdown
Member

This adds a dependency for testing. Therefore I am -1

@raghavrv
Copy link
Copy Markdown
Member Author

How about we simply convert all docstrings to comments instead...?

@GaelVaroquaux
Copy link
Copy Markdown
Member

GaelVaroquaux commented Feb 15, 2015 via email

@amueller
Copy link
Copy Markdown
Member

I guess I'm also +1 on just using comments everywhere.

@amueller
Copy link
Copy Markdown
Member

FYI when I introduced the generators into the common tests, I was thinking about a nice way to set the names. A decorator for the check functions would probably be a nice and easy solution.

ogrisel pushed a commit that referenced this pull request Feb 24, 2015
… to avoid description ptoblems with nose (Related to issue #4250)
@raghavrv raghavrv force-pushed the travis_ignore_docstring branch 3 times, most recently from 8297dec to 3a62aa3 Compare February 28, 2015 04:02
@raghavrv
Copy link
Copy Markdown
Member Author

@amueller @jnothman Do you feel decorators for generators are needed?

For this test and a generator without description set to it...

def test_discretenb_partial_fit():
    for cls in [MultinomialNB, BernoulliNB]:
        yield check_partial_fit, cls

The output when it passes is -

sklearn.tests.test_naive_bayes.test_discretenb_partial_fit(<class 'sklearn.naive_bayes.MultinomialNB'>,) ... ok
sklearn.tests.test_naive_bayes.test_discretenb_partial_fit(<class 'sklearn.naive_bayes.BernoulliNB'>,) ... ok

The output when it fails is -

sklearn.tests.test_naive_bayes.test_discretenb_partial_fit(<class 'sklearn.naive_bayes.MultinomialNB'>,) ... FAIL
sklearn.tests.test_naive_bayes.test_discretenb_partial_fit(<class 'sklearn.naive_bayes.BernoulliNB'>,) ... ok
.
.
.
======================================================================
FAIL: sklearn.tests.test_naive_bayes.test_discretenb_partial_fit(<class 'sklearn.naive_bayes.MultinomialNB'>,)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File ".../scikit-learn/sklearn/tests/test_naive_bayes.py", line 120, in check_partial_fit
    assert False
AssertionError

----------------------------------------------------------------------

@amueller
Copy link
Copy Markdown
Member

amueller commented Mar 1, 2015

decorators are for another PR.

@raghavrv
Copy link
Copy Markdown
Member Author

raghavrv commented Mar 1, 2015

But do you think we need them? given that, with a decorator, we simply get the description unlike the more detailed sklearn.tests.test_naive_bayes.test_discretenb_partial_fit(<class 'sklearn.naive_bayes.BernoulliNB'>,) ? ( The line of error is anyway going to be shown in the Traceback... The arguments passed to the generator could be useful right? )

@amueller
Copy link
Copy Markdown
Member

amueller commented Mar 1, 2015

yes, I think they would be good, if we can keep the name of the estimator in the string. If not, you are right. Maybe that was the reason why I didn't go for the decorator approach.

@amueller
Copy link
Copy Markdown
Member

amueller commented Mar 1, 2015

The thing is that you don't know which check is running from the output, and for example which one gives a warning or takes long etc.

@raghavrv raghavrv force-pushed the travis_ignore_docstring branch from a1972a8 to 451e1b6 Compare March 10, 2015 13:47
@raghavrv
Copy link
Copy Markdown
Member Author

@amueller Could you take a look at this one? I know this has a huge diff, but should be easy to review since this just changes docstring to comments...

(Kindly review the last two commits separately as they are not related to the docstring --> comment conversion)

@raghavrv
Copy link
Copy Markdown
Member Author

Also as you had suggested, I'll make a separate PR for the decorator for test gens.!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why this? It looks odd.

@amueller
Copy link
Copy Markdown
Member

apart from inline comment lgtm

@raghavrv
Copy link
Copy Markdown
Member Author

Done! Please take a final look! @ogrisel could I trouble you for a 2nd review?

@amueller amueller changed the title [MRG] Prevent nose from using docstring to name the tests in results [MRG + 1] Prevent nose from using docstring to name the tests in results Mar 10, 2015
@amueller
Copy link
Copy Markdown
Member

looks fine now.

@raghavrv
Copy link
Copy Markdown
Member Author

@ogrisel Any reviews? (sorry to trouble you with multiple PR review requests :p)

@amueller
Copy link
Copy Markdown
Member

can you rebase please?

@raghavrv raghavrv force-pushed the travis_ignore_docstring branch from c575676 to 07d6e27 Compare March 20, 2015 19:00
@raghavrv
Copy link
Copy Markdown
Member Author

Done :)

@raghavrv raghavrv closed this Mar 21, 2015
@raghavrv raghavrv force-pushed the travis_ignore_docstring branch from 764c640 to 3b32099 Compare March 21, 2015 05:00
rasbt pushed a commit to rasbt/scikit-learn that referenced this pull request Apr 6, 2015
… to avoid description ptoblems with nose (Related to issue scikit-learn#4250)
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.

4 participants