GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — pytest approx wrong formatting return - printing all values as wrong. · Issue #12444 · pytest-dev/pytest

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

New issue
Copy link
New issue
Copy link
Closed
#13815
Closed
pytest approx wrong formatting return - printing all values as wrong.#12444
#13815
Copy link
Labels
topic: rewriterelated to the assertion rewrite mechanismtype: bugproblem that needs to be addressed

Description

@natsala13
natsala13
opened on Jun 10, 2024
Issue body actions

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 =========================================

Activity

  1. Zac-HD
    added
    type: bugproblem that needs to be addressed
    topic: rewriterelated to the assertion rewrite mechanism
    on Jun 24, 2024
  2. nicoddemus
    added a commit that references this issue on Jan 25, 2026

    Fix pytest.approx to correctly take account Mapping keys order to com…

    This issue will close once commit e95a843 is merged into the 'main' branch.
    e95a843
  3. nicoddemus
    closed this as completedin #13815on Jan 25, 2026
  4. patchback
    added a commit that references this issue on Jan 25, 2026

    Fix pytest.approx to correctly take account Mapping keys order to com…

    This issue will close once commit dd6001f is merged into the 'main' branch.
    dd6001f
  5. nicoddemus
    added a commit that references this issue on Jan 25, 2026

    Fix pytest.approx to correctly take account Mapping keys order to com…

    This issue will close once commit 72ae54c is merged into the 'main' branch.
    72ae54c
  6. luketainton
    added a commit that references this issue on Apr 13, 2026

    build(security): Update dependency pytest to v9.0.3 [SECURITY] (#217)

    aaa06c7
  7. 736-c41-2c1-e464fc974
    added a commit that references this issue on Apr 19, 2026

    chore(deps): update root dev dependencies (patch)

    2e66ad0
  8. MateoGreil
    added a commit that references this issue on Jul 4, 2026

    🔒️ Update dependency pytest to v9 [SECURITY] (#16)

    d97ea28
  9. luketainton
    added a commit that references this issue on Jul 19, 2026

    [SECURITY] Update dependency pytest to v9 [SECURITY] (#2)

    fca183b
  10. Djeex
    added a commit that references this issue on Aug 31, 2026

    Update dependency pytest to v9 (#35)

    f96ce2f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: rewriterelated to the assertion rewrite mechanismtype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.