Let unittest._ShouldStop propagate through retry() so subTest+failfast works (#26616)

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cheng Wan
2026-05-28 16:26:17 -07:00
committed by GitHub
co-authored by Claude Opus 4.7
parent ec78fa6518
commit 4f92e63c99
+8
View File
@@ -72,6 +72,7 @@ from typing import (
Union,
)
from unittest import SkipTest
from unittest.case import _ShouldStop
from urllib.parse import unquote, urlparse
import numpy as np
@@ -2771,6 +2772,13 @@ def retry(
except SkipTest:
# Do NOT retry skipped tests - used in CI and unittest
raise
except _ShouldStop:
# `unittest.case._ShouldStop` is raised by `subTest.__exit__`
# when a subtest fails/skips and `result.failfast` is True
# (CI invokes `python3 file.py -f`). It signals the outer
# `testPartExecutor` to stop the test method cleanly; do
# NOT retry, just propagate so unittest handles it.
raise
except Exception as e:
traceback.print_exc()