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

Missing necessary parentheses and not allowing equality #67

Open
bmw opened this issue Feb 15, 2023 · 1 comment
Open

Missing necessary parentheses and not allowing equality #67

bmw opened this issue Feb 15, 2023 · 1 comment

Comments

@bmw
Copy link

bmw commented Feb 15, 2023

In my work on certbot/certbot#9585, unittest2pytest rewrote these lines:

self.assertAlmostEqual(mock_sleep.call_args_list[1][0][0], interval - 1, delta=1)
self.assertAlmostEqual(mock_sleep.call_args_list[2][0][0], interval/2 - 1, delta=1)

as

assert abs(mock_sleep.call_args_list[1][0][0]-interval - 1) < 1
assert abs(mock_sleep.call_args_list[2][0][0]-interval/2 - 1) < 1

This is incorrect for two reasons:

  1. Parentheses should be added around the 2nd argument to assertAlmostEqual (or the - 1 changed to + 1).
  2. assertAlmostEqual doesn't error if the difference between the first two arguments equals the delta argument.

(With that said, I just ran unittest2pytest on 28k lines of real test code and this was the only problem I encountered other than the pytest.raises limitation described at the bottom of your README. Nice work!)

@bmw bmw changed the title Missing necessary parentheses Missing necessary parentheses and not allowing equality Feb 15, 2023
@RonnyPfannschmidt
Copy link
Member

We should have a pytest.approx there instead of the cheap imitation

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

No branches or pull requests

2 participants