MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / is_flaky

Function is_flaky

diffusers/src/diffusers/utils/testing_utils.py:783–816  ·  view source on GitHub ↗

To decorate flaky tests. They will be retried on failures. Args: max_attempts (`int`, *optional*, defaults to 5): The maximum number of attempts to retry the flaky test. wait_before_retry (`float`, *optional*): If provided, will wait that number of s

(max_attempts: int = 5, wait_before_retry: Optional[float] = None, description: Optional[str] = None)

Source from the content-addressed store, hash-verified

781
782# Copied from https://github.com/huggingface/transformers/blob/000e52aec8850d3fe2f360adc6fd256e5b47fe4c/src/transformers/testing_utils.py#L1905
783def is_flaky(max_attempts: int = 5, wait_before_retry: Optional[float] = None, description: Optional[str] = None):
784 """
785 To decorate flaky tests. They will be retried on failures.
786
787 Args:
788 max_attempts (`int`, *optional*, defaults to 5):
789 The maximum number of attempts to retry the flaky test.
790 wait_before_retry (`float`, *optional*):
791 If provided, will wait that number of seconds before retrying the test.
792 description (`str`, *optional*):
793 A string to describe the situation (what / where / why is flaky, link to GH issue/PR comments, errors,
794 etc.)
795 """
796
797 def decorator(test_func_ref):
798 @functools.wraps(test_func_ref)
799 def wrapper(*args, **kwargs):
800 retry_count = 1
801
802 while retry_count < max_attempts:
803 try:
804 return test_func_ref(*args, **kwargs)
805
806 except Exception as err:
807 print(f"Test failed with {err} at try {retry_count}/{max_attempts}.", file=sys.stderr)
808 if wait_before_retry is not None:
809 time.sleep(wait_before_retry)
810 retry_count += 1
811
812 return test_func_ref(*args, **kwargs)
813
814 return wrapper
815
816 return decorator
817
818
819# Taken from: https://github.com/huggingface/transformers/blob/3658488ff77ff8d45101293e749263acf437f4d5/src/transformers/testing_utils.py#L1787

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected