Here are two variables: earnings_forecast
, actual_earning
(numerical variables)
I want to assert if both these variables are equal with a diffe
You can use the new isclose function introduced in Python 3.5
PEP 485 adds the math.isclose() and cmath.isclose() functions which tell whether two values are approximately equal or “close” to each other. Whether or not two values are considered close is determined according to given absolute and relative tolerances. Relative tolerance is the maximum allowed difference between isclose arguments, relative to the larger absolute value
import math
a = 100.0
b = 102.0
c = 103.0
assert math.isclose(a,b, rel_tol=0.02)
assert math.isclose(a,c, rel_tol=0.02)