Skip to content

Broken output when a multidimensional NumPy array fails to be approximate something #3712

@Wrzlprmft

Description

@Wrzlprmft

Consider the following example comparing two multidimensional arrays using approx:

from pytest import approx
import numpy as np

def test_something():
	shape = (5,4)
	X = np.ones(shape)
	Y = np.ones(shape)*2
	assert X==approx(Y)

The error thrown by PyTest is:

E    assert array([[1., 1., 1., 1.],\n       [1., 1., 1., 1.],\n       [1., 1., 1., 1.],\n       [1., 1., 1., 1.],\n       [1., 1., 1., 1.]]) == <[TypeError("only size-1 arrays can be converted to Python scalars") raised in repr()] ApproxNumpy object at 0x7f63bda42a58>
E     +  where <[TypeError("only size-1 arrays can be converted to Python scalars") raised in repr()] ApproxNumpy object at 0x7f63bda42a58> = approx(array([[2., 2., 2., 2.],\n       [2., 2., 2., 2.],\n       [2., 2., 2., 2.],\n       [2., 2., 2., 2.],\n       [2., 2., 2., 2.]]))

This is confusing since at first glance it seems that the problem is that I tried to convert some array in an inappropriate manner, while actually the assertion failed.

My PyTest version is 3.3.2.

Metadata

Metadata

Assignees

Labels

type: bugproblem that needs to be addressed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions