pytest-dev / unittest2pytest

helps rewriting Python `unittest` test-cases into `pytest` test-cases
GNU General Public License v3.0
128 stars 27 forks source link

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

Closed janosh closed 2 weeks ago

janosh commented 1 year ago

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