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

Taught in

References