pytest.approx
A pytest helper that compares numbers as equal if they are within a small tolerance of each other.
In more detail
It exists because floating-point results rarely match a hand-written decimal exactly. By default it allows a relative tolerance of one part in a million; pass abs= or rel= when you know how much difference matters.
Example
assert convert(7, "EUR") == pytest.approx(8.246)Related terms
- floating-point number — A number with a fractional part stored in binary, which can only approximate most decimal values.
- assertion — A check that a condition is true, which stops a test or program with a failure if it is false.
Taught in
- Making Failures Explain Themselves — Automated Testing, TDD & Quality Engineering