Add custom approx() to help with floating point <= / >= testing#4504
Conversation
I've gone ahead and done this, and added a test to verify it behaves as expected. The definition lives in the root of the testbed tests, so it should be accessible from all testbed tests. Notably, it's not available to the core tests; if we like this approach here, it might be worth implementing it there too. |
approx() to help with floating point <= / >= testing
johnzhou721
left a comment
There was a problem hiding this comment.
This looks great!! I really liked how you subclassed ApproxScalar rather than pulling your own custom class, which was what I've done in these situations in the past.
freakboy3742
left a comment
There was a problem hiding this comment.
I agree the decision on disallowing <=/>= comparisons is... odd. I don't love the fact that we're reaching into an internal API to implement this - but it works, and we'll get plenty of warning if it ever changes/breaks.
Marking as approved; one suggestion inline tied to the pytest version compatibility thing.
748d370 to
6087e2b
Compare
6087e2b to
cf51148
Compare
For reference, this is my current setup:
I found that every single test in the iOS testbed was erroring out for me in setup:
Floating-point inaccuracy strikes again. Unfortunately, because
pytest.approxintentionally doesn't support inequalities (explained by a note in the docs that I still find baffling), we can't simply writea >= approx(b); we instead needa > b or a == approx(b).This isn't the first time I've seen an issue like this crop up; I'm starting to wonder if it would be worth writing our own subclass or helper function to handle floating-point
<=/>=comparisons.PR Checklist: