Skip to content

Commit ae1c491

Browse files
committed
connect
1 parent a4224d7 commit ae1c491

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

_unittests/ut_torch_models/test_hghub_model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
hide_stdout,
77
requires_torch,
88
requires_transformers,
9+
ignore_errors,
910
)
1011
from onnx_diagnostic.torch_models.hghub.model_inputs import (
1112
config_class_from_architecture,
@@ -102,6 +103,7 @@ def test_get_untrained_model_with_inputs_text2text_generation(self):
102103
@hide_stdout()
103104
@requires_torch("2.7", "reduce test time")
104105
@requires_transformers("4.50", "reduce test time")
106+
@ignore_errors(OSError) # connectivity issues may happen
105107
def test_get_untrained_model_Ltesting_models(self):
106108
# UNHIDE=1 python _unittests/ut_torch_models/test_hghub_model.py -k L -f
107109
def _diff(c1, c2):

onnx_diagnostic/ext_test_case.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,34 @@ def call_f(self):
108108
return wrapper
109109

110110

111+
def ignore_errors(errors: Union[Exception, Tuple[Exception]]) -> Callable:
112+
"""
113+
Catches exception, skip the test if the error is expected sometimes.
114+
115+
:param errors: errors to ignore
116+
"""
117+
118+
def wrapper(fct):
119+
if errors is None:
120+
raise AssertionError(f"errors cannot be None for '{fct}'.")
121+
122+
def call_f(self):
123+
try:
124+
return fct(self)
125+
except errors as e:
126+
raise unittest.SkipTest( # noqa: B904
127+
f"expecting error {e.__class__.__name__}: {e}"
128+
)
129+
130+
try: # noqa: SIM105
131+
call_f.__name__ = fct.__name__
132+
except AttributeError:
133+
pass
134+
return call_f
135+
136+
return wrapper
137+
138+
111139
def hide_stdout(f: Optional[Callable] = None) -> Callable:
112140
"""
113141
Catches warnings, hides standard output.

0 commit comments

Comments
 (0)