Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing assert functions give confusing message on failure #751

Open
olliesilvester opened this issue Jan 27, 2025 · 2 comments
Open

Testing assert functions give confusing message on failure #751

olliesilvester opened this issue Jan 27, 2025 · 2 comments

Comments

@olliesilvester
Copy link
Contributor

olliesilvester commented Jan 27, 2025

assert_reading and assert_configuration give a confusing full diff when an equality fails, making it hard to see the actual issue.

As an example, if we change test_assert_reading in tests/core/test_signal.py so that the dummy_reading has timestamp: 5, this is the test output

AssertionError: assert {'mock_readable-float_array': {'value': array([  1.1231,  -2.3   , 451.15  ,   6.6233], dtype=float32), 'timestamp': 366659.164213077, 'alarm_severity': 0}, 'mock_readable-int_array': {'value': array([1, 2, 4, 7], dtype=int8), 'timestamp': 366659.164199919, 'alarm_severity': 0}, 'mock_readable-int_value': {'value': 188, 'timestamp': 366659.164185914, 'alarm_severity': 0}} == {'mock_readable-int_value': {'alarm_severity': 0, 'timestamp': 5, 'value': 188 ± 1.9e-04}, 'mock_readable-int_array': {'alarm_severity': 0, 'timestamp': <ANY>, 'value': approx([1 ± 1.0e-06, 2 ± 2.0e-06, 4 ± 4.0e-06, 7 ± 7.0e-06])}, 'mock_readable-float_array': {'alarm_severity': 0, 'timestamp': <ANY>, 'value': approx([1.1231 ± 1.1e-06, -2.3 ± 2.3e-06, 451.15 ± 4.5e-04, 6.6233 ± 6.6e-06])}}
  
  Common items:
  {'mock_readable-float_array': {'alarm_severity': 0,
                                 'timestamp': 366659.164213077,
                                 'value': array([  1.1231,  -2.3   , 451.15  ,   6.6233], dtype=float32)},
   'mock_readable-int_array': {'alarm_severity': 0,
                               'timestamp': 366659.164199919,
                               'value': array([1, 2, 4, 7], dtype=int8)}}
  Differing items:
  {'mock_readable-int_value': {'alarm_severity': 0, 'timestamp': 366659.164185914, 'value': 188}} != {'mock_readable-int_value': {'alarm_severity': 0, 'timestamp': 5, 'value': 188 ± 1.9e-04}}
  
  Full diff:
    {
        'mock_readable-float_array': {
            'alarm_severity': 0,
  -         'timestamp': <ANY>,
  -         'value': approx([1.1231 ± 1.1e-06, -2.3 ± 2.3e-06, 451.15 ± 4.5e-04, 6.6233 ± 6.6e-06]),
  +         'timestamp': 366659.164213077,
  +         'value': array([  1.1231,  -2.3   , 451.15  ,   6.6233], dtype=float32),
        },
        'mock_readable-int_array': {
            'alarm_severity': 0,
  -         'timestamp': <ANY>,
  -         'value': approx([1 ± 1.0e-06, 2 ± 2.0e-06, 4 ± 4.0e-06, 7 ± 7.0e-06]),
  +         'timestamp': 366659.164199919,
  +         'value': array([1, 2, 4, 7], dtype=int8),
        },
        'mock_readable-int_value': {
            'alarm_severity': 0,
  -         'timestamp': 5,
  +         'timestamp': 366659.164185914,
  ?                      ++++ +++++++++++
  -         'value': 188 ± 1.9e-04,
  ?                     ----------
  +         'value': 188,
        },
    }

Really, there is only one value causing an issue. It would be easier to write and fix tests if the output here only contained the breaking differences.

@olliesilvester olliesilvester added the bug Something isn't working label Jan 27, 2025
@olliesilvester olliesilvester added Developer Experience and removed bug Something isn't working labels Jan 27, 2025
@olliesilvester olliesilvester changed the title Testing assert functions don't work with approximate values Testing assert functions give confusing message on failure Jan 27, 2025
@olliesilvester
Copy link
Contributor Author

Issue rewritten from what I'd originally put since I thought the full diff was actually causing the errors

@coretl
Copy link
Collaborator

coretl commented Jan 28, 2025

I think this is contributing to the problem:
pytest-dev/pytest#3638

A possible fix is to allow the user to omit timestamp and alarm severity from the expected values, and if not present then put the actual values into the expected values so the diff is smaller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants