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)
| 683 | |
| 684 | # Copied from https://github.com/huggingface/transformers/blob/000e52aec8850d3fe2f360adc6fd256e5b47fe4c/src/transformers/testing_utils.py#L1905 |
| 685 | def is_flaky(max_attempts: int = 5, wait_before_retry: Optional[float] = None, description: Optional[str] = None): |
| 686 | """ |
| 687 | To decorate flaky tests. They will be retried on failures. |
| 688 | |
| 689 | Args: |
| 690 | max_attempts (`int`, *optional*, defaults to 5): |
| 691 | The maximum number of attempts to retry the flaky test. |
| 692 | wait_before_retry (`float`, *optional*): |
| 693 | If provided, will wait that number of seconds before retrying the test. |
| 694 | description (`str`, *optional*): |
| 695 | A string to describe the situation (what / where / why is flaky, link to GH issue/PR comments, errors, |
| 696 | etc.) |
| 697 | """ |
| 698 | |
| 699 | def decorator(test_func_ref): |
| 700 | @functools.wraps(test_func_ref) |
| 701 | def wrapper(*args, **kwargs): |
| 702 | retry_count = 1 |
| 703 | |
| 704 | while retry_count < max_attempts: |
| 705 | try: |
| 706 | return test_func_ref(*args, **kwargs) |
| 707 | |
| 708 | except Exception as err: |
| 709 | print(f"Test failed with {err} at try {retry_count}/{max_attempts}.", file=sys.stderr) |
| 710 | if wait_before_retry is not None: |
| 711 | time.sleep(wait_before_retry) |
| 712 | retry_count += 1 |
| 713 | |
| 714 | return test_func_ref(*args, **kwargs) |
| 715 | |
| 716 | return wrapper |
| 717 | |
| 718 | return decorator |
| 719 | |
| 720 | |
| 721 | # Taken from: https://github.com/huggingface/transformers/blob/3658488ff77ff8d45101293e749263acf437f4d5/src/transformers/testing_utils.py#L1787 |
nothing calls this directly
no outgoing calls
no test coverage detected