use of pytest.approx
Seems like we have a lot of tests that use pytest.appox
in a wrong way.
In [1]: import pytest
In [2]: pytest.approx(1,17)
Out[2]: 1 ± 1.7e+01
Lets say we want to check if 1 is approximately 17:
Here is what should be done
In [4]: bool(pytest.approx(1)==17)
Out[4]: False
Here is what is done in some tests (dangerous), in this case 17 is interpreted as acceptable relative error
In [3]: bool(pytest.approx(1,17))
Out[3]: True
A brief git grep -n pytest.approx | awk '!/==/'
gave me the following list of suspicios lines:
tests/controllers_hw/test_axis.py:51: assert pytest.approx(axis.velocity, test_velocity)
tests/controllers_hw/test_ct2_acq.py:107: assert pytest.approx(data, expected_data)
tests/controllers_sw/test_wago.py:704: assert pytest.approx(wago.controller.devreadnocachephys(key), values)
tests/controllers_sw/test_wago.py:705: assert pytest.approx(wago.controller.get(logical_name), values)
tests/motors/test_group.py:54: assert pytest.approx(robz.position, 1)
tests/motors/test_group.py:55: assert pytest.approx(roby.position, 1)
tests/motors/test_tango_axis.py:59: assert pytest.approx(value, 3)
tests/motors/test_trajectories.py:30: assert pytest.approx(traj.pvt[:-1]["position"], 2.5)
tests/motors/test_trajectories.py:38: assert pytest.approx(s1f.offset, -0.5)
tests/motors/test_trajectories.py:39: assert pytest.approx(s1b.offset, -0.5)
tests/scans/test_cen_com.py:106: assert pytest.approx(p, center)
tests/scans/test_continuous_soft_scan.py:127: assert pytest.approx(
tests/scans/test_continuous_soft_scan.py:198: assert pytest.approx(
tests/scans/test_data_watch.py:105: assert pytest.approx(m1.position, end_pos)
tests/scans/test_step_by_step.py:24: assert pytest.approx(robz2.position, 0.1234567)
tests/scans/test_step_by_step.py:27: assert pytest.approx(robz2.tolerance, 1e-4)
tests/scans/test_step_by_step.py:51: assert pytest.approx(robz2.tolerance, 1e-4)
tests/tango/test_wago_ds.py:29: assert pytest.approx(value1, value2[0])
tests/tango/test_wago_ds.py:58: pytest.approx(dev_proxy.command_inout("DevReadNoCachePhys", (20))[0], .1)
tests/test_counters.py:253: assert pytest.approx(stats.mean, numpy.mean(dat))
tests/test_counters.py:255: assert pytest.approx(stats.std, numpy.std(dat))
tests/test_counters.py:256: assert pytest.approx(stats.var, numpy.var(dat))
tests/test_counters.py:399: assert pytest.approx(integ_stats.mean, numpy.mean(new_dat))
tests/test_counters.py:401: assert pytest.approx(integ_stats.std, numpy.std(new_dat))
tests/test_counters.py:402: assert pytest.approx(integ_stats.var, numpy.var(new_dat))
tests/test_counters.py:405: assert pytest.approx(integ_stats.p2v, numpy.max(new_dat) - numpy.min(new_dat))