Skip to content

[MRG + 1] [TST] (half-cosmetic) use less nose.tools import to simplify future transition to py.test#7384

Merged
amueller merged 7 commits intoscikit-learn:masterfrom
code-of-kpp:lessnoseimports
Oct 7, 2016
Merged

[MRG + 1] [TST] (half-cosmetic) use less nose.tools import to simplify future transition to py.test#7384
amueller merged 7 commits intoscikit-learn:masterfrom
code-of-kpp:lessnoseimports

Conversation

@code-of-kpp
Copy link
Copy Markdown

Reference Issue

Contributing my experiments with ideas from #7319 issue

What does this implement/fix? Explain your changes.

Replaces most occasions of import nose and from nose.tools import with from sklearn.utils.testing import

Any other comments?

For now we can't get rid of nosetests completely because numpy.testing is built on top of them and there is a lot of numpy.testing imports.
But with that and with strong recommendation to not import anything from nose we will be able to replace it as soon as numpy will.

Also, with this PR setting $NOSETESTS to pytest should just work without any significant code changes.

@code-of-kpp
Copy link
Copy Markdown
Author

There is no new functionality here and changes are very simple, so I really believe it should me merged ASAP. The sooner it is merged, the less work would be required to cleanup those imports from other PRs

@jnothman
Copy link
Copy Markdown
Member

My concern is the load on the core dev team to review, reflect on whether
there's anything essential missing from the features being release, and get
it out the door. This is really low priority in comparison. Remind in a
week.

On 12 September 2016 at 06:59, Konstantin Podshumok <
notifications@github.com> wrote:

There is no new functionality here and changes are very simple, so I
really believe it should me merged ASAP. The sooner it is merged, the less
work would be required to cleanup those imports from other PRs


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#7384 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEz6-b86cO8gT1rkriEvxnWBggnHxV5ks5qpGvEgaJpZM4J5nFT
.

@amueller
Copy link
Copy Markdown
Member

I think @mblondel did something similar at some point and got some push-back. but then it was cosmetic, now it's actually quite useful to hide the source so we can move.

@code-of-kpp
Copy link
Copy Markdown
Author

May be I should extend this PR to full "Move to py.test" branch? Currently it is more or less cosmetic. But as I said above every new merged PR can introduce new nose imports, keeping it in actual state may not wroth it

@mblondel
Copy link
Copy Markdown
Member

I think @mblondel did something similar at some point and got some push-back

You have a good memory :)

@rth
Copy link
Copy Markdown
Member

rth commented Oct 3, 2016

Also, with this PR setting $NOSETESTS to pytest should just work without any significant code changes.

This would be quite useful. Could you rebase please? Also maybe add a [MRG] tag to the title if you happy for this to be merged. Even if new PR introduce new nose imports, this is still an improvement over the current state.

Copy link
Copy Markdown
Member

@amueller amueller left a comment

Choose a reason for hiding this comment

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

Yeah I think this would be great to have.

# Nose < 1.0.0
SkipTest = unittest.case.SkipTest
except AttributeError:
# Python <= 2.6, we stil need nose here
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.

we dropped support for this.

@jnothman
Copy link
Copy Markdown
Member

jnothman commented Oct 4, 2016

I think this would be good to merge ASAP. Please address the fact that we no longer support Python 2.6 (at master)

@amueller
Copy link
Copy Markdown
Member

amueller commented Oct 5, 2016

Also please rebase.

@lesteve
Copy link
Copy Markdown
Member

lesteve commented Oct 6, 2016

Thanks for rebasing ! Out of curiosity, is this PR supposed to remove all nose imports? I still see a few of them:

$ git grep -P 'from nose|import nose'
sklearn/utils/testing.py:from nose.tools import raises
sklearn/utils/testing.py:from nose import with_setup
sklearn/utils/testing.py:    from nose import SkipTest
sklearn/utils/tests/test_testing.py:    from nose.tools import assert_less
sklearn/utils/tests/test_testing.py:    from nose.tools import assert_greater

I understand that raises, and with_setup are still needed, SkipTest as well only for Python 2.6. Having said that, the two last ones can be removed, right ?

Given the probability of conflicts with other changes, I would be fine leaving the nose imports for Python 2.6 and do the Python 2.6 support removal in a separate PR.

@code-of-kpp
Copy link
Copy Markdown
Author

Currently:

$ grep -n -E '^\s*[^#]+*nose' `find . -name '*.py'`
./sklearn/utils/tests/test_testing.py:22:    from nose.tools import assert_less
./sklearn/utils/tests/test_testing.py:36:    from nose.tools import assert_greater
./sklearn/utils/testing.py:51:from nose.tools import raises
./sklearn/utils/testing.py:52:from nose import with_setup
./sklearn/utils/testing.py:85:    from nose import SkipTest
./sklearn/externals/joblib/testing.py:28:    from nose.tools import assert_raises_regex
./sklearn/externals/joblib/testing.py:32:        from nose.tools import assert_raises_regexp as assert_raises_regex

imports in test_testing are py2.6-compatible to be removed, the same with SkipTest in testing.py:85.
I don't know what to do with externals.joblib.testing

with_setup can be replaced in most places with setup_module or with pytest.fixture
raises can be replaced directly with pytest.raises when time comes.

Please note, that numpy uses nose so all imports of numpy.testing really imply nose.tools.

One thing I noticed during my work on this PR is active usage of from numpy.testing import assert_equal where people really just mean usual assert_equal or asset_array_equal. I think usage of this function may be confusing and should be avoided in the future, for example consider:

>>> from nose import tools
>>> from numpy import testing
>>> 
>>> testing.assert_equal([], ())  # passes
>>> tools.assert_equal([], ())
Traceback (most recent call last)\
...
AssertionError: [] != ()

Should we document guidelines about nose and numpy.testing? Where to put these docs?

Can I remove py2.6 from .travis.yml or should I wait for master? After that I can remove py2.6-related commits without breaking CI.

@GaelVaroquaux
Copy link
Copy Markdown
Member

GaelVaroquaux commented Oct 6, 2016 via email

@code-of-kpp code-of-kpp changed the title use less nose.tools import to simplify future transition to py.test [MRG] [TST] (half-cosmetic) use less nose.tools import to simplify future transition to py.test Oct 6, 2016
@lesteve
Copy link
Copy Markdown
Member

lesteve commented Oct 6, 2016

Open an issue in the joblib repo. If the devs are in favor of moving to py.test, make a PR there.

Yeah do that, I'd be more than favourable of using joblib for a test bed of moving to py.test. For completeness, sklearn/externals/joblib is always an unmodified release of joblib so it shouldn't be changed within scikit-learn.

@lesteve
Copy link
Copy Markdown
Member

lesteve commented Oct 6, 2016

Can I remove py2.6 from .travis.yml or should I wait for master? After that I can remove py2.6-related commits without breaking CI.

My personal preference would be to do the Python 2.6 support removal in a separate PR. There is quite a few things to remove not related to nose or testing (the OrderedDict backport jumps to mind) and single-purpose PR are far easier to merge.

I think we should keep the .travis.yml Python 2.6 build but replace Python 2.6 by Python 2.7 in order to test old versions of dependencies.

@code-of-kpp
Copy link
Copy Markdown
Author

code-of-kpp commented Oct 6, 2016

Having said that, the two last ones can be removed, right ?

Those are imports are used to test if some sklearn's and noses's assert_* functions do the same.
With py2.6 there are some other nose imports and I believe these tests make sense.

Even more, until we have a nose dependency there is a sense in extending them - after all, I introduced some new (untested) code...

Copy link
Copy Markdown
Member

@lesteve lesteve left a comment

Choose a reason for hiding this comment

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

LGTM, as I said above I am fine merging as is and removing the Python 2.6 support in a separate PR.

@lesteve lesteve changed the title [MRG] [TST] (half-cosmetic) use less nose.tools import to simplify future transition to py.test [MRG] + 1 [TST] (half-cosmetic) use less nose.tools import to simplify future transition to py.test Oct 7, 2016
@lesteve lesteve changed the title [MRG] + 1 [TST] (half-cosmetic) use less nose.tools import to simplify future transition to py.test [MRG + 1] [TST] (half-cosmetic) use less nose.tools import to simplify future transition to py.test Oct 7, 2016
@amueller amueller merged commit 9b2aac9 into scikit-learn:master Oct 7, 2016
@amueller
Copy link
Copy Markdown
Member

amueller commented Oct 7, 2016

Thanks. Let's see where this'll bite us first ;)

amueller added a commit to amueller/scikit-learn that referenced this pull request Oct 14, 2016
…y future transition to py.test (scikit-learn#7384)

* use less nose.tools import to simplify future transition to activly developing test suites/runners

* assert_equal -> assert_array_equal in test_feature_hasher_pairs_with_string_values

and one missed ImportError that should be replaced with AttributeError

* test for py2.6 compat with except AttributeError

* fix importing of SkipTest

* force using nose in python2.6 for now

* there was no assert_dict_equal in py2.6. but we can use assert_equal

although failed test will look a little bit ugly

* remove nose imports from doc/datasets

# Conflicts:
#	sklearn/neighbors/tests/test_dist_metrics.py
#	sklearn/utils/tests/test_fixes.py
Sundrique pushed a commit to Sundrique/scikit-learn that referenced this pull request Jun 14, 2017
…y future transition to py.test (scikit-learn#7384)

* use less nose.tools import to simplify future transition to activly developing test suites/runners

* assert_equal -> assert_array_equal in test_feature_hasher_pairs_with_string_values

and one missed ImportError that should be replaced with AttributeError

* test for py2.6 compat with except AttributeError

* fix importing of SkipTest

* force using nose in python2.6 for now

* there was no assert_dict_equal in py2.6. but we can use assert_equal

although failed test will look a little bit ugly

* remove nose imports from doc/datasets
paulha pushed a commit to paulha/scikit-learn that referenced this pull request Aug 19, 2017
…y future transition to py.test (scikit-learn#7384)

* use less nose.tools import to simplify future transition to activly developing test suites/runners

* assert_equal -> assert_array_equal in test_feature_hasher_pairs_with_string_values

and one missed ImportError that should be replaced with AttributeError

* test for py2.6 compat with except AttributeError

* fix importing of SkipTest

* force using nose in python2.6 for now

* there was no assert_dict_equal in py2.6. but we can use assert_equal

although failed test will look a little bit ugly

* remove nose imports from doc/datasets
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.

8 participants