Skip to content
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

Fix ValueErrors raised when numpy iterables use == in failed #41

Merged
merged 7 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
- name: Install dependencies
run: |
python setup.py develop
pip install numpy

- name: Test
shell: 'script -q -e -c "bash {0}"'
Expand Down
4 changes: 4 additions & 0 deletions pytest_icdiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def pytest_assertrepr_compare(config, op, left, right):
return
except TypeError:
pass
except ValueError:
# ValueErrors are raised when numpy / pandas errors are checked
# Bail out of generating a diff and use pytest default output
return

half_cols = COLS / 2 - MARGINS

Expand Down
23 changes: 23 additions & 0 deletions tests/test_pytest_icdiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from unittest import mock
import pytest
import re
import sys
from pprintpp import pformat

YELLOW_ON = '\x1b[1;33m'
Expand Down Expand Up @@ -292,3 +293,25 @@ def test_one():
output = testdir.runpytest('-vv', '--color=yes', '-r=no').stdout.str()
assert len(output.splitlines()) < 50
assert "---" in output # context split marker


@pytest.mark.skipif('numpy' not in sys.modules, reason="requires numpy library")
def test_np_arrays_can_use_equals(testdir) -> None:
"""
Numpy iterables will fall back to pytest default output
"""
testdir.makepyfile("""
import numpy as np

def test():
result = np.array([1, 2, 3])

assert all(result == 2)
""")

result = testdir.runpytest()

output = result.stdout.str()
assert 'ValueError' not in output
assert 'AssertionError' in output
assert 'where False = all(equals failed' not in output, 'pytest-icdiff not used'