From ad5ddaf55a71ebf640043d34c79cf3672c86be5c Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 1 Aug 2018 07:28:39 -0300 Subject: [PATCH] Simplify is_numpy_array as suggested in review --- src/_pytest/python_api.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/_pytest/python_api.py b/src/_pytest/python_api.py index bbbc144ee..66b9473b7 100644 --- a/src/_pytest/python_api.py +++ b/src/_pytest/python_api.py @@ -531,17 +531,11 @@ def _is_numpy_array(obj): Return true if the given object is a numpy array. Make a special effort to avoid importing numpy unless it's really necessary. """ - import inspect - - for cls in inspect.getmro(type(obj)): - if cls.__module__ == "numpy": - try: - import numpy as np - - return isinstance(obj, np.ndarray) - except ImportError: - pass + import sys + np = sys.modules.get("numpy") + if np is not None: + return isinstance(obj, np.ndarray) return False