diff --git a/test/conftest.py b/test/conftest.py index f549b6b..b3264ea 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -19,13 +19,20 @@ import random -import beartype import jax.random as jr import pytest import typeguard -@pytest.fixture(params=[typeguard.typechecked, beartype.beartype]) +try: + import beartype +except ImportError: + typecheck_params = [typeguard.typechecked] +else: + typecheck_params = [typeguard.typechecked, beartype.beartype] + + +@pytest.fixture(params=typecheck_params) def typecheck(request): return request.param @@ -37,6 +44,3 @@ def getkey(): return jr.PRNGKey(random.randint(0, 2**31 - 1)) return _getkey - - -ParamException = (TypeError, beartype.roar.BeartypeCallHintParamViolation) diff --git a/test/helpers.py b/test/helpers.py index 8e5289e..3829bbf 100644 --- a/test/helpers.py +++ b/test/helpers.py @@ -17,12 +17,17 @@ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -import beartype import equinox as eqx -ParamError = (TypeError, beartype.roar.BeartypeCallHintParamViolation) -ReturnError = (TypeError, beartype.roar.BeartypeCallHintReturnViolation) +try: + import beartype +except ImportError: + ParamError = TypeError + ReturnError = TypeError +else: + ParamError = (TypeError, beartype.roar.BeartypeCallHintParamViolation) + ReturnError = (TypeError, beartype.roar.BeartypeCallHintReturnViolation) @eqx.filter_jit diff --git a/test/test_import_hook.py b/test/test_import_hook.py index 2881394..8f81762 100644 --- a/test/test_import_hook.py +++ b/test/test_import_hook.py @@ -32,10 +32,17 @@ def test_import_hook_typeguard(): def test_import_hook_beartype(): - hook = install_import_hook("import_hook_tester_beartype", ("beartype", "beartype")) - import import_hook_tester_beartype # noqa: F401 + try: + import beartype # noqa: F401 + except ImportError: + pass + else: + hook = install_import_hook( + "import_hook_tester_beartype", ("beartype", "beartype") + ) + import import_hook_tester_beartype # noqa: F401 - hook.uninstall() + hook.uninstall() def test_import_hook_transitive():