Skip to content

Commit

Permalink
test: ignore import errors while inferring available transformers in …
Browse files Browse the repository at this point in the history
…tests.
  • Loading branch information
qthequartermasterman committed May 9, 2024
1 parent 3e80d6a commit 84185cb
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions tests/unit/test_huggingface.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 84185cb

Please sign in to comment.