From 84185cb66fcec5f50aad09e38b0026624ca5862a Mon Sep 17 00:00:00 2001 From: qthequartermasterman Date: Wed, 8 May 2024 21:51:57 -0500 Subject: [PATCH] test: ignore import errors while inferring available transformers in tests. --- tests/unit/test_huggingface.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/unit/test_huggingface.py b/tests/unit/test_huggingface.py index 1bffa7b..c2bd45e 100644 --- a/tests/unit/test_huggingface.py +++ b/tests/unit/test_huggingface.py @@ -1,12 +1,12 @@ """Tests for the transformers strategies.""" +import contextlib import os -import unittest from types import ModuleType -from typing import Any, Final -import pytest +from typing import Final import hypothesis +import pytest import transformers from hypothesis import strategies as st @@ -37,12 +37,13 @@ def test_officially_supported_transformers( # We will dynamically test all available transformers models. for module in transformers.models.__dict__.values(): - if type(module) is transformers.utils.import_utils._LazyModule: - for attr in module._modules: - if "modeling" in attr: - getattr(module, attr) - elif type(module) is ModuleType: - print(module.__name__, module.__dict__) + with contextlib.suppress(ImportError): + if type(module) is transformers.utils.import_utils._LazyModule: + for attr in module._modules: + if "modeling" in attr: + getattr(module, attr) + elif type(module) is ModuleType: + print(module.__name__, module.__dict__) AVAILABLE_TRANSFORMERS: list[type[transformers.PreTrainedModel]] = inspection_util.get_all_subclasses( transformers.PreTrainedModel