unittest2pytest icon indicating copy to clipboard operation
unittest2pytest copied to clipboard

Use `pytest.approx` in `fixes.AlmostOp`

Open janosh opened this issue 2 years ago • 0 comments

Closes #63.

Change AlmostOp() to rewrite self.assertAlmostEqual(3, 3.0) to 3 == approx(3.0) instead of round(abs(3 - 3.0), 7) == 0.

Still needs tests. Also currently requires adding from pytest import approx though that can be done with something like isort --add-import 'from pytest import approx' $(git status -s | cut -c4-).

Here's an example diff generated by the new AlmostOp():

Screenshot 2023-01-19 at 21 09 25

janosh avatar Jan 20 '23 05:01 janosh