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 Raises misleading error for Sequences/Collections containing different strings · Issue #13010 · pytest-dev/pytest

pytest.approx Raises misleading error for Sequences/Collections containing different strings #13010

New issue
Copy link
New issue
Copy link
Closed
Closed
pytest.approx Raises misleading error for Sequences/Collections containing different strings#13010
Copy link
Labels
topic: approxrelated to pytest.approx function

Description

@marcelotrevisani
marcelotrevisani
opened on Nov 29, 2024
Issue body actions

Hi folks,

I was using pytest.approx and I found a scenario when using approx in a collection or sequence that can have multiples types, the problem arise when doing:

def test_approx_str():
    assert [1.0, 2.0, "abc"] == approx([1.0, 2.0, "aaa"])

I was expecting pytest to bypass the approx for str type, but I am seeing the following error:

    def test_approx_str():
>       assert [1.0, 2.0, "abc"] == approx([1.0, 2.0, "aaa"])
E       AssertionError: assert [1.0, 2.0, 'abc'] == approx([1.0 ±...2.0e-06, aaa])
E         
E         (pytest_assertion plugin: representation of details failed: /tmp/test_a/.venv/lib/python3.12/site-packages/_pytest/python_api.py:343: TypeError: unsupported operand type(s) for -: 'str' and 'str'.
E          Probably an object has a faulty __repr__.)

test_foo.py:5: AssertionError

let me know if you need more info about this

Package   Version
--------- -------
iniconfig 2.0.0
packaging 24.2
pluggy    1.5.0
pytest    8.3.3
  • a detailed description of the bug or problem you are having
  • output of pip list from the virtual environment you are using
  • pytest and operating system versions
  • minimal example if possible

Activity

  1. graingert commented on Nov 30, 2024

    @graingert
    graingert
    on Nov 30, 2024
    Member
    More actions

    Related: #12839

  2. Zac-HD
    added
    topic: approxrelated to pytest.approx function
    on Nov 30, 2024
  3. nicoddemus
    closed this as completedin d65d991on Nov 30, 2024
  4. daria-shaw
    added a commit that references this issue on Nov 30, 2024

    approx: do not raise error in mixed sequence/collections

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

    chore(deps): update dependency pytest to v9 (#305)

    4b75154
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: approxrelated to pytest.approx function

    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.