Skip to content
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

pytest follow up #323

Closed
9 of 15 tasks
massich opened this issue Aug 18, 2017 · 3 comments
Closed
9 of 15 tasks

pytest follow up #323

massich opened this issue Aug 18, 2017 · 3 comments
Labels
Type: Enhancement Indicates new feature requests

Comments

@massich
Copy link
Contributor

massich commented Aug 18, 2017

Migrate the value validation

  • assert_equal (nose2pytest) [MRG] nosetests to pytests #310

  • assert_almost_equal (or floating point comparison [MRG] nosetests to pytests #310)
    Instead of using the nose2pytest's default transformation which changes assert_almost_equal(a, b, delta[,msg]) into assert abs(a-b) <= delta[, msg], we chose to use the approx helper function that translates to assert a == approx(b, [abs=delta])[, msg]. In this manner:

    + from pytest import approx
    -    assert_equal(score, 0.65025)
    +    assert score == approx(0.65025)
  • assert_array_equal

  • assert_array_almost_equal

  • assert_allclose

Migrate raising checks

  • assert_raise [MRG] Migrate raising errors from nose to pytest #321
    Based on the documentation here, assert_raises(ValueError, func, *args, **kwargs ) can become: pytest.raises(ValueError, func, *args, **kwargs ), pytest.raises(ValueError, "func(*args, **kwargs)" ) or with raises(ValueError): func(*args, **kwargs). The first option can be done using find-replace but we latter is preferred for readability. (it has been carried out manually)
    here is an example:

    -    assert_raises(TypeError, Pipeline)
    +    with raises(TypeError):
    +        Pipeline()
  • assert_raises_regex [MRG] Migrate raising errors from nose to pytest #321
    See match(regexp) here
    In example:

    -    assert_raises_regex(ValueError, "has to be one of",
    -                        ada.fit_sample, X, Y)
    +    with raises(ValueError, match="has to be one of"):
    +        ada.fit_sample(X, Y)
  • assert_raise_message ([MRG] Migrate raising errors from nose to pytest #321: f8ad59e)
    Use assert + regex match.

  • assert_warns
    Deprecation warnings are treated different (see this)

  • assert_warns_message

  • assert_no_warnings

  • my_assert (this is a custom assert with in a loop here)

yield

  • yield

Set-up and tare-down become fixtures

Other things to migrate

  • Update the CI (at master)
  • Update Makefiles (at master)
@massich
Copy link
Contributor Author

massich commented Dec 1, 2017

assert_array_equal, assert_array_almost_equal, etc belong to numpy not nosetests. So we don't need to translate them. I would like to translate them but they are not supported by numpy.
I'll check whenever is not an array and change it by pytest.

otherwise, the Issue can be closed.

@massich
Copy link
Contributor Author

massich commented Dec 1, 2017

assert_allclose can be changed by pytest assert.

assert_allclose(grid.best_score_, 0.92, rtol=R_TOL)

@glemaitre
Copy link
Member

addressed by #470

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Indicates new feature requests
Projects
None yet
Development

No branches or pull requests

2 participants