odlgroup / odl

Operator Discretization Library https://odlgroup.github.io/odl/
Mozilla Public License 2.0
372 stars 105 forks source link

Use pytest.approx more #1257

Open kohr-h opened 6 years ago

kohr-h commented 6 years ago

The pytest.approx function can be used for scalar comparison, but also for sequences, dicts, and since version 3.2.0 also for Numpy arrays. What it doesn't handle is nested sequences, so we can't replace everything by it.

But maybe we can reduce our own logic significantly and delegate more to pytest.approx?

adler-j commented 6 years ago

Is there some way for us to hook into pytest.approx and modify it? If we solve

We should be all fine

kohr-h commented 6 years ago

Looking at the code, I have to revise my opinion. So (1) no, there's no way to hook into it other than forking pytest and adding more ApproxMyclass classes, and (2) the array comparison is quite lame, using np.nditer which is slow, and no optimization for two arrays (in the style of np.allclose).

I guess I was expecting too much.

The relevant code is here: https://github.com/pytest-dev/pytest/blob/master/_pytest/python_api.py