Skip to content

pytest follow up #323

Closed
Closed
@massich

Description

@massich

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions