I am writing some unittests in python that are testing if I receive an integer. However sometimes this integer can be off by 1 or 2 and I don\'t really care. Essentially I w
Python has a built in function you may use for this: assertAlmostEqual.
self.assertAlmostEqual(myinteger, 999, delta=1)
# is equivalent to
self.assertTrue(998 <= myinteger <= 1000)
# ... but gives better error messages.
The optional parameter delta specifies the allowed distance from the value you're testing.