Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • bliss bliss
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 542
    • Issues 542
    • List
    • Boards
    • Service Desk
    • Milestones
  • Jira
    • Jira
  • Merge requests 145
    • Merge requests 145
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • BlissBliss
  • blissbliss
  • Issues
  • #1565
Closed
Open
Issue created Apr 01, 2020 by Linus Pithan@pithanOwner

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))
Assignee
Assign to
Time tracking