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

Printing detailed diff with pytest.approx fails due to ± character #2111

Closed
kerrick-lyft opened this Issue Dec 1, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@kerrick-lyft

kerrick-lyft commented Dec 1, 2016

OS: OS X 10.11.6 (also present on Ubuntu 14.04)
Python version: 2.7.12
pytest version: 3.0.4
Output of pip list:

pip (9.0.1)
py (1.4.31)
pytest (3.0.4)
setuptools (30.0.0)
wheel (0.30.0a0)

This code:

import pytest

def test_foo():
    assert [3] == [pytest.approx(4)]

produces the below output. It looks like the detailed diff can't render due to the ± character in the __repr__ of pytest.approx.

(venv) ➜  /tmp py.test pytest_broken.py 
============================= test session starts ==============================
platform darwin -- Python 2.7.12, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
rootdir: /private/tmp, inifile: 
plugins: cov-2.2.1, mock-0.11.0
collected 1 items 

pytest_broken.py F

=================================== FAILURES ===================================
___________________________________ test_foo ___________________________________

    def test_foo():
>       assert [3] == [pytest.approx(4)]
E       assert [3] == [4 ± 4.0e-06]
E         (pytest_assertion plugin: representation of details failed.  Probably an object has a faulty __repr__.)
E         /usr/local/lib/python2.7/site-packages/_pytest/assertion/util.py:228: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 2: ordinal not in range(128)

pytest_broken.py:4: AssertionError
============================ pytest-warning summary ============================
WC1 None pytest_funcarg__cov: declaring fixtures using "pytest_funcarg__" prefix is deprecated and scheduled to be removed in pytest 4.0.  Please remove the prefix and use the @pytest.fixture decorator instead.
================= 1 failed, 1 pytest-warnings in 0.03 seconds ==================

@nicoddemus

This comment has been minimized.

Member

nicoddemus commented Dec 2, 2016

Thanks!

@nicoddemus

This comment has been minimized.

Member

nicoddemus commented Dec 2, 2016

(You can update your pytest-cov plugin to get rid of that warning 😉 )

@nicoddemus nicoddemus added the type: bug label Dec 2, 2016

nicoddemus added a commit to nicoddemus/pytest that referenced this issue Dec 2, 2016

nicoddemus added a commit to nicoddemus/pytest that referenced this issue Dec 2, 2016

nicoddemus added a commit to nicoddemus/pytest that referenced this issue Dec 2, 2016

This was referenced Mar 5, 2018

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