From 071ed86a4ff33b4b3bc72b60a97fccd60bf1d40a Mon Sep 17 00:00:00 2001 From: Maxim Vafin Date: Fri, 18 Oct 2024 18:18:27 +0200 Subject: [PATCH] [TESTS] Fix retry mechanism to raise if retry didn't help --- .../py_frontend_tests/test_torchvision_preprocessor.py | 4 +++- tests/layer_tests/pytorch_tests/pytorch_layer_test_class.py | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/layer_tests/py_frontend_tests/test_torchvision_preprocessor.py b/tests/layer_tests/py_frontend_tests/test_torchvision_preprocessor.py index 94060bf982ad96..1ec25f6c07f500 100644 --- a/tests/layer_tests/py_frontend_tests/test_torchvision_preprocessor.py +++ b/tests/layer_tests/py_frontend_tests/test_torchvision_preprocessor.py @@ -32,15 +32,17 @@ def forward(self, data): def _infer_pipelines(test_input, preprocess_pipeline, input_channels=3): retries = 0 max_retries = 3 + last_e = None while retries < max_retries: try: return _infer_pipelines_impl(test_input, preprocess_pipeline, input_channels) except RuntimeError as e: # This is a potentially sporadic issue print(f"An error occurred: {e}. Retrying...") + last_e = e retries += 1 else: - print("Max retries reached. Function execution failed.") + raise RuntimeError("Max retries reached. Function execution failed.") from last_e def _infer_pipelines_impl(test_input, preprocess_pipeline, input_channels=3): diff --git a/tests/layer_tests/pytorch_tests/pytorch_layer_test_class.py b/tests/layer_tests/pytorch_tests/pytorch_layer_test_class.py index 4d1582f0061d59..a44ca8c0117a4b 100644 --- a/tests/layer_tests/pytorch_tests/pytorch_layer_test_class.py +++ b/tests/layer_tests/pytorch_tests/pytorch_layer_test_class.py @@ -73,19 +73,21 @@ def _test(self, model, ref_net, kind, ie_device, precision, ir_version, infer_ti **kwargs): retries = 0 max_retries = 3 + last_e = None while retries < max_retries: try: return self._test_impl(model, ref_net, kind, ie_device, precision, ir_version, infer_timeout, dynamic_shapes, **kwargs) except RuntimeError as e: # This is a potentially sporadic issue print(f"An error occurred: {e}. Retrying...") + last_e = e retries += 1 else: - print("Max retries reached. Function execution failed.") + raise RuntimeError("Max retries reached. Function execution failed.") from last_e def _test_impl(self, model, ref_net, kind, ie_device, precision, ir_version, infer_timeout=60, dynamic_shapes=True, - **kwargs): + **kwargs): """ :param enabled_transforms/disabled_transforms: string with idxs of transforms that should be enabled/disabled. Example: "transform_1,transform_2"