`delta` arg in self.assertAlmostEqual
dannysepler opened this issue · comments
this one seems tricky
self.assertAlmostEqual(a, b, delta=0.5) # assert a - b <= 0.5
How about this? I think this is equivalent.
assert a == pytest.approx(b, abs=0.5)
yes! i think so too. run pytest on this, should all pass
import unittest
import pytest
def test_fail():
with pytest.raises(AssertionError):
assert 0.1 == pytest.approx(0.7, abs=0.5)
def test_success():
assert 0.1 == pytest.approx(0.5, abs=0.5)
class TestCase(unittest.TestCase):
def test_assert_almost_eq_when_succeeds(self):
self.assertAlmostEqual(0.1, 0.5, delta=0.5)
def test_assert_almost_eq(self):
with self.assertRaises(AssertionError):
self.assertAlmostEqual(0.1, 0.7, delta=0.5)