Use pytest.approx in tests.helpers.utils

See #1877
This commit is contained in:
Florian Bruhin 2016-08-22 07:39:11 +02:00
parent 853f4cd9d8
commit 4658bdcacf
2 changed files with 4 additions and 1 deletions

View File

@ -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)

View File

@ -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(