Skip to content
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 AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ Leonardus Chen
Lev Maximov
Levon Saldamli
Lewis Cowles
Liam DeVoe
Llandy Riveron Del Risco
Loic Esteve
lovetheguitar
Expand Down
1 change: 1 addition & 0 deletions changelog/13563.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:func:`pytest.approx` now only imports ``numpy`` if NumPy is already in ``sys.modules``. This fixes unconditional import behavior introduced in `8.4.0`.
7 changes: 2 additions & 5 deletions src/_pytest/python_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,9 @@ def is_bool(val: Any) -> bool:
# Check if `val` is a native bool or numpy bool.
if isinstance(val, bool):
return True
try:
import numpy as np

if np := sys.modules.get("numpy"):
return isinstance(val, np.bool_)
except ImportError:
return False
return False

asarray = _as_numpy_array(actual)
if asarray is not None:
Expand Down