File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
_unittests/ut_torch_models Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 66 hide_stdout ,
77 requires_torch ,
88 requires_transformers ,
9+ ignore_errors ,
910)
1011from 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 ):
Original file line number Diff line number Diff 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+
111139def hide_stdout (f : Optional [Callable ] = None ) -> Callable :
112140 """
113141 Catches warnings, hides standard output.
You can’t perform that action at this time.
0 commit comments