Skip to content

Commit 33c0b06

Browse files
committed
Fix error in approx's repr with complex numbers
Fix #2082
1 parent 38f7562 commit 33c0b06

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
subtle bugs (`#2078`_).
88
Thanks `@nicoddemus`_ for the PR.
99

10+
* Fix error message using ``approx`` with complex numbers (`#2082`_).
11+
Thanks `@adler-j`_ for the report and `@nicoddemus`_ for the PR.
12+
13+
*
1014

1115
* Cope gracefully with a .pyc file with no matching .py file (`#2038`_). Thanks
1216
`@nedbat`_.
@@ -15,10 +19,12 @@
1519

1620
*
1721

22+
.. _@adler-j: https://github.com/adler-j
1823
.. _@nedbat: https://github.com/nedbat
1924

2025
.. _#2038: https://github.com/pytest-dev/pytest/issues/2038
2126
.. _#2078: https://github.com/pytest-dev/pytest/issues/2078
27+
.. _#2082: https://github.com/pytest-dev/pytest/issues/2082
2228

2329

2430
3.0.4

_pytest/python.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,9 @@ def __init__(self, expected, rel=None, abs=None):
14191419
self.rel = rel
14201420

14211421
def __repr__(self):
1422+
if isinstance(self.expected, complex):
1423+
return str(self.expected)
1424+
14221425
# Infinities aren't compared using tolerances, so don't show a
14231426
# tolerance.
14241427
if math.isinf(self.expected):

testing/python/approx.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def test_repr_string(self):
2828
print(approx(inf))
2929
print(approx(1.0, rel=nan))
3030
print(approx(1.0, rel=inf))
31+
print(approx(1.0j, rel=inf))
3132

3233
def test_operator_overloading(self):
3334
assert 1 == approx(1, rel=1e-6, abs=1e-12)

0 commit comments

Comments
 (0)