Skip to content
Merged
Changes from 1 commit
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
15 changes: 9 additions & 6 deletions pint/testsuite/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,13 +447,16 @@ def test_trapz(self):
)

@helpers.requires_array_function_protocol()
# NP2: Remove this when we only support np>=2.0
@pytest.mark.skipif(
np.lib.NumpyVersion(np.__version__) < "2.0.0b1",
reason="trapezoid added in numpy2",
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might need to make this a function. Something like

def requires_numpy_2(reason=None):
    if reason is None:
        reason = "requires numpy >= 2"
    return pytest.mark.skipif(np.lib.NumpyVersion(np.__version__) < "2.0.0b1", reason=reason)

...

@requires_numpy_2(reason="trapezoid added in numpy2")
def test_trapezoid(self):
    ...

could work. Otherwise it is possible to skip the entire test module if numpy is not available:

pytest.importorskip("numpy")

def test_trapezoid(self):
# NP2: Remove this when we only support np>=2.0
if np.lib.NumpyVersion(np.__version__) >= "2.0.0b1":
helpers.assert_quantity_equal(
np.trapezoid([1.0, 2.0, 3.0, 4.0] * self.ureg.J, dx=1 * self.ureg.m),
7.5 * self.ureg.J * self.ureg.m,
)
helpers.assert_quantity_equal(
np.trapezoid([1.0, 2.0, 3.0, 4.0] * self.ureg.J, dx=1 * self.ureg.m),
7.5 * self.ureg.J * self.ureg.m,
)

@helpers.requires_array_function_protocol()
def test_dot(self):
Expand Down