diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 282221fd..b7da6da1 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -97,6 +97,22 @@ def f(module: ModulePointer, expected: Any, fn_name: str = "main"): def run_int_fn(): return _run_fn("run_int_function") + @pytest.fixture -def run_float_fn(): - return _run_fn("run_float_function") +def run_float_fn_approx(): + """Like run_int_fn, but takes optional additional parameters `rel`, `abs` and `nan_ok` + as per `pytest.approx`.""" + run_fn = _run_fn("run_float_function") + + def run_approx( + hugr: Package, + expected: float, + fn_name: str = "main", + *, + rel: float | None = None, + abs: float | None = None, + nan_ok: bool = False, + ): + return run_fn(hugr, pytest.approx(expected, rel=rel, abs=abs, nan_ok=nan_ok)) + + return run_approx diff --git a/tests/integration/test_arithmetic.py b/tests/integration/test_arithmetic.py index d8bbc348..5a8448aa 100644 --- a/tests/integration/test_arithmetic.py +++ b/tests/integration/test_arithmetic.py @@ -251,7 +251,7 @@ def run_rem() -> int: run_int_fn(hugr, expected=2, fn_name="run_rem") -def test_angle_exec(validate, run_float_fn): +def test_angle_exec(validate, run_float_fn_approx): module = GuppyModule("test_angle_exec") module.load_all(angles) @@ -266,4 +266,4 @@ def main() -> float: hugr = module.compile() validate(hugr) import math - run_float_fn(hugr, expected=pytest.approx(-6 * math.pi)) + run_float_fn_approx(hugr, expected=-6 * math.pi)