gh-133089: Use original timeout value for TimeoutExpired when the func subprocess.run is called with a timeout (GH-133103)

Signed-off-by: Manjusaka <me@manjusaka.me>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
This commit is contained in:
Nadeshiko Manju 2025-05-05 09:15:31 +08:00 committed by GitHub
parent 51d2459e4d
commit 2bbcaedb75
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 46 additions and 4 deletions

View file

@ -162,6 +162,20 @@ class ProcessTestCase(BaseTestCase):
[sys.executable, "-c", "while True: pass"],
timeout=0.1)
def test_timeout_exception(self):
try:
subprocess.run(['echo', 'hi'], timeout = -1)
except subprocess.TimeoutExpired as e:
self.assertIn("-1 seconds", str(e))
else:
self.fail("Expected TimeoutExpired exception not raised")
try:
subprocess.run(['echo', 'hi'], timeout = 0)
except subprocess.TimeoutExpired as e:
self.assertIn("0 seconds", str(e))
else:
self.fail("Expected TimeoutExpired exception not raised")
def test_check_call_zero(self):
# check_call() function with zero return code
rc = subprocess.check_call(ZERO_RETURN_CMD)