Plasmapy: Change sequential tests to fixture and class->function based ones

Created on 17 Dec 2017  路  6Comments  路  Source: PlasmaPy/PlasmaPy

Our tests are a terrible mess.... Look at this!

def test_gyroradius():
    r"""Test the gyroradius function in parameters.py."""

    assert gyroradius(B, T_e).unit == u.m

    assert gyroradius(B, 25 * u.m / u.s).unit == u.m

    assert gyroradius(T_e, B) == gyroradius(B, T_e)

    assert gyroradius(V, B) == gyroradius(B, V)

    assert gyroradius(B, V) == gyroradius(B, -V)

(and so on...)

How are you supposed to differentiate which assert failed?
What are these asserts doing? How do we know the tests are meaningful without any comments describing what is being tested?

Heavy refactoring is required. I think a class based approach, like what I've done with Test_kappa_thermal_speed, makes sense. It allows us to organize multiple tests under the header of testing a single function. One assert or one failure in a with context per method.

Documentation medium high Refactoring Testing

Most helpful comment

Okay, I agree that a class based approach to this would be nice.

I might be able to take a shot on this over the next few days.

All 6 comments

Okay, I agree that a class based approach to this would be nice.

I might be able to take a shot on this over the next few days.

I've been gradually tackling this for functions where I've had to write new tests. So it should already be partially done. test_parameters.py will probably be the worst off.

I'm going to procrastinate Fortran and make test_dispersion.py less horrible. 馃捑 馃枼 馃柋 鈱笍

I'm assuming that we are shooting for class based tests for v0.1 with possibility of switching over to fixtures in the future. Is that a safe assumption?

I'd say we're shooting for whatever tests work for now, with cleanup intended in the future :laughing:

I think what we have is good enough for now. We could really use a cleanup in the future.

Was this page helpful?
0 / 5 - 0 ratings