Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytest approx wrong formatting return - printing all values as wrong. #12444

Open
natsala13 opened this issue Jun 10, 2024 · 0 comments · May be fixed by #12445
Open

pytest approx wrong formatting return - printing all values as wrong. #12444

natsala13 opened this issue Jun 10, 2024 · 0 comments · May be fixed by #12445
Labels
topic: rewrite related to the assertion rewrite mechanism type: bug problem that needs to be addressed

Comments

@natsala13
Copy link

Hey! Thanks for this great library!
I am using pytest.approx to compare between 2 dicts (which are not in the same order), whenever the 2 dicts are equal the asserts passes. but if only 1 element is wrong the assert fails (as expected) but the output message shows as if all values were different instead of printing only the wrong one.

pytest == 8.2.0
python == 3.11.7
Ubuntu == 20.04

def test_approx_dict_equal():  # This tests passes!
    assert {'a': 1, 'c': 3} == pytest.approx({'a': 1, 'c': 3})


def test_approx_dict_ordered():  # This tests fails as expected and return CORRECT output
    assert {'a': 1, 'c': 5} == pytest.approx({'a': 1, 'c': 3})


def test_approx_dict_unordered():  # This tests fails as expected and return WRONG output
    assert {'c': 5, 'a': 1} == pytest.approx({'a': 1, 'c': 3})

and the output I get from the two failing tests is:

================================================= short test summary info ==================================================
FAILED tests/test_debug_pytest.py::test_approx_dict_ordered - AssertionError: assert {'a': 1, 'c': 5} == approx({'a': 1 ± 1.0e-06, 'c': 3 ± 3.0e-06})

  comparison failed. Mismatched elements: 1 / 2:
  Max absolute difference: 2
  Max relative difference: 0.6666666666666666
  Index | Obtained | Expected
  c     | 5        | 3 ± 3.0e-06
FAILED tests/test_debug_pytest.py::test_approx_dict_unordered - AssertionError: assert {'c': 5, 'a': 1} == approx({'a': 1 ± 1.0e-06, 'c': 3 ± 3.0e-06})

  comparison failed. Mismatched elements: 2 / 2:
  Max absolute difference: 4
  Max relative difference: 4.0
  Index | Obtained | Expected
  a     | 1        | 1 ± 1.0e-06
  c     | 5        | 3 ± 3.0e-06
======================================== 2 failed, 1 passed, 4 deselected in 0.37s =========================================
@Zac-HD Zac-HD added type: bug problem that needs to be addressed topic: rewrite related to the assertion rewrite mechanism labels Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: rewrite related to the assertion rewrite mechanism type: bug problem that needs to be addressed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants