Skip to content

Commit 1b00453

Browse files
authored
Merge pull request #41 from jamescooke/fix-numpy-iterables
Fix ValueErrors raised when numpy iterables use `==` in failed
2 parents e817937 + 8c6a27e commit 1b00453

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
- name: Install dependencies
1717
run: |
1818
python setup.py develop
19+
pip install numpy
1920
2021
- name: Test
2122
shell: 'script -q -e -c "bash {0}"'

pytest_icdiff.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ def pytest_assertrepr_compare(config, op, left, right):
2323
return
2424
except TypeError:
2525
pass
26+
except ValueError:
27+
# ValueErrors are raised when numpy / pandas errors are checked
28+
# Bail out of generating a diff and use pytest default output
29+
return
2630

2731
half_cols = COLS / 2 - MARGINS
2832

tests/test_pytest_icdiff.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from unittest import mock
33
import pytest
44
import re
5+
import sys
56
from pprintpp import pformat
67

78
YELLOW_ON = '\x1b[1;33m'
@@ -292,3 +293,25 @@ def test_one():
292293
output = testdir.runpytest('-vv', '--color=yes', '-r=no').stdout.str()
293294
assert len(output.splitlines()) < 50
294295
assert "---" in output # context split marker
296+
297+
298+
@pytest.mark.skipif('numpy' not in sys.modules, reason="requires numpy library")
299+
def test_np_arrays_can_use_equals(testdir) -> None:
300+
"""
301+
Numpy iterables will fall back to pytest default output
302+
"""
303+
testdir.makepyfile("""
304+
import numpy as np
305+
306+
def test():
307+
result = np.array([1, 2, 3])
308+
309+
assert all(result == 2)
310+
""")
311+
312+
result = testdir.runpytest()
313+
314+
output = result.stdout.str()
315+
assert 'ValueError' not in output
316+
assert 'AssertionError' in output
317+
assert 'where False = all(equals failed' not in output, 'pytest-icdiff not used'

0 commit comments

Comments
 (0)