From 4658bdcacf4388f8754e12e7f4ec32775bec4e11 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 22 Aug 2016 07:39:11 +0200 Subject: [PATCH] Use pytest.approx in tests.helpers.utils See #1877 --- tests/helpers/test_helper_utils.py | 1 + tests/helpers/utils.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/helpers/test_helper_utils.py b/tests/helpers/test_helper_utils.py index 1265204ec..65c7c29a1 100644 --- a/tests/helpers/test_helper_utils.py +++ b/tests/helpers/test_helper_utils.py @@ -45,6 +45,7 @@ def test_partial_compare_equal(val1, val2): ({1: 1}, {1: [1]}, "Different types (int, list) -> False"), ({'a': [1, 2, 3]}, {'a': [..., 3]}, "2 != 3"), ("foo*baz", "foobarbaz", "'foo*baz' != 'foobarbaz' (pattern matching)"), + (23.42, 13.37, "23.42 != 13.37 (float comparison)"), ]) def test_partial_compare_not_equal(val1, val2, error): outcome = utils.partial_compare(val1, val2) diff --git a/tests/helpers/utils.py b/tests/helpers/utils.py index 2ca7aa6f2..c8cf820cd 100644 --- a/tests/helpers/utils.py +++ b/tests/helpers/utils.py @@ -26,6 +26,8 @@ import re import pprint import os.path +import pytest + class PartialCompareOutcome: @@ -84,7 +86,7 @@ def _partial_compare_list(val1, val2, *, indent): def _partial_compare_float(val1, val2, *, indent): - if abs(val1 - val2) < 0.00001: + if val1 == pytest.approx(val2): return PartialCompareOutcome() return PartialCompareOutcome("{!r} != {!r} (float comparison)".format(