aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_subprocess.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2025-03-05 11:51:33 +0100
committerGitHub <noreply@github.com>2025-03-05 10:51:33 +0000
commit67a942d4272145ccdbdf4ceff31318e176f71355 (patch)
treebd08c04a37dc509eb384ea8b33302e4e6e66808d /Lib/test/test_subprocess.py
parent63d25f8d0c4f4626fb9f1131402d95fdaca34a57 (diff)
downloadcpython-67a942d4272145ccdbdf4ceff31318e176f71355.tar.gz
cpython-67a942d4272145ccdbdf4ceff31318e176f71355.zip
gh-116742: Fix subprocess test_check_output_timeout() (#130836)
Fix a race condition in test_check_output_timeout() of test_subprocess. Don't write into stdout anymore, since there is no reliable way to synchronize the parent and the child processes. Change the timeout from 3 seconds to 0.1 seconds, and remove @requires_resource('walltime') decorator.
Diffstat (limited to 'Lib/test/test_subprocess.py')
-rw-r--r--Lib/test/test_subprocess.py27
1 files changed, 5 insertions, 22 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index e45701dfe03..645aa2cc7d9 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -269,21 +269,13 @@ class ProcessTestCase(BaseTestCase):
self.assertIn('stdin', c.exception.args[0])
self.assertIn('input', c.exception.args[0])
- @support.requires_resource('walltime')
def test_check_output_timeout(self):
# check_output() function with timeout arg
with self.assertRaises(subprocess.TimeoutExpired) as c:
output = subprocess.check_output(
[sys.executable, "-c",
- "import sys, time\n"
- "sys.stdout.write('BDFL')\n"
- "sys.stdout.flush()\n"
- "time.sleep(3600)"],
- # Some heavily loaded buildbots (sparc Debian 3.x) require
- # this much time to start and print.
- timeout=3)
- self.fail("Expected TimeoutExpired.")
- self.assertEqual(c.exception.output, b'BDFL')
+ "import time; time.sleep(3600)"],
+ timeout=0.1)
def test_call_kwargs(self):
# call() function with keyword args
@@ -1694,20 +1686,11 @@ class RunFuncTestCase(BaseTestCase):
self.assertIn('stdin', c.exception.args[0])
self.assertIn('input', c.exception.args[0])
- @support.requires_resource('walltime')
def test_check_output_timeout(self):
with self.assertRaises(subprocess.TimeoutExpired) as c:
- cp = self.run_python((
- "import sys, time\n"
- "sys.stdout.write('BDFL')\n"
- "sys.stdout.flush()\n"
- "time.sleep(3600)"),
- # Some heavily loaded buildbots (sparc Debian 3.x) require
- # this much time to start and print.
- timeout=3, stdout=subprocess.PIPE)
- self.assertEqual(c.exception.output, b'BDFL')
- # output is aliased to stdout
- self.assertEqual(c.exception.stdout, b'BDFL')
+ cp = self.run_python(
+ "import time; time.sleep(3600)",
+ timeout=0.1, stdout=subprocess.PIPE)
def test_run_kwargs(self):
newenv = os.environ.copy()