diff --git a/CHANGES.rst b/CHANGES.rst index cba441a..44b6c3b 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,7 +1,8 @@ 1.8.0 (unreleased) ================== -- No changes yet. +- Fixing ``FLOAT_CMP`` not comparing complex numbers with a negative + imaginary part, like ``(1.5-2.5j)``. [#328] 1.7.1 (2026-01-26) ================== diff --git a/pytest_doctestplus/output_checker.py b/pytest_doctestplus/output_checker.py index 53dd6f5..93e1afd 100644 --- a/pytest_doctestplus/output_checker.py +++ b/pytest_doctestplus/output_checker.py @@ -64,7 +64,7 @@ def __init__(self): # floats in the 'want' string may contain ellipses want_floats = got_floats + r'(\.{3})?' - front_sep = r'\s|[*+-,<=(\[]' + front_sep = r'\s|[*+\-,<=(\[]' back_sep = front_sep + r'|[>j)\]}]' fbeg = fr'^{got_floats}(?={back_sep}|$)' diff --git a/tests/test_doctestplus.py b/tests/test_doctestplus.py index 91542ce..25f3b96 100644 --- a/tests/test_doctestplus.py +++ b/tests/test_doctestplus.py @@ -147,6 +147,28 @@ def g(): reprec.assertoutcome(failed=0, passed=1) +def test_float_cmp_complex(testdir): + testdir.makeini( + """ + [pytest] + doctestplus = enabled + """ + ) + p = testdir.makepyfile( + """ + def g(): + ''' + >>> x = complex(1/3., -2/3.) + >>> x # doctest: +FLOAT_CMP + (0.333333-0.666666j) + ''' + pass + """ + ) + reprec = testdir.inline_run(p, "--doctest-plus") + reprec.assertoutcome(failed=0, passed=1) + + def test_float_cmp_global(testdir): testdir.makeini(""" [pytest]