I am trying to compare 2 values (float) using squish and it works fine sometimes, but fails few times. It is very inconsistent. Can someone help me how to use isclose for comparing float values.
Following is my script:
Xposition_set = waitForObject("{id='textBoxGoto_Sample_X'}").text
Xposition_setValue = round(float(Xposition_set), 2)
Xposition_displayed = waitForObject("{id='dbxX' nativeObject.DataContext.Name='" + str(positionList[Index])+ "'}").text
Xposition_displayedValue = round(float(Xposition_displayed), 2)
test.compare(Xposition_setValue, Xposition_displayedValue, GetTestCaseNumber() + "X -Positions matches")
What you are trying should work in general, but because of missing information it is not possible to find out what particular problem you are running into with the above code.
Here is an example Squish test script (for Squish for Windows, which you seem to use) which does what you are asking for with the Squish Addressbook example:
Please note that this test script is for Python 3.5.x due to math.isclose(), so it won't work with a default Squish binary package as those ship with Python 2.7.x (contact Squish technical support to obtain a Squish binary package with a different Python version).