Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Lib/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ def __init__(self, cmd, timeout, output=None, stderr=None):
self.stderr = stderr

def __str__(self):
return ("Command '%s' timed out after %s seconds" %
(self.cmd, self.timeout))
return f"Command {self.cmd!r} timed out after {self.timeout} seconds"

@property
def stdout(self):
Expand Down
13 changes: 13 additions & 0 deletions Lib/test/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -2449,6 +2449,19 @@ def test_CalledProcessError_str(self):
err = subprocess.CalledProcessError(-9876543, "fake cmd")
self.assertEqual(str(err), "Command 'fake cmd' died with unknown signal 9876543.")

def test_TimeoutExpired_str(self):
# timeout command string
err = subprocess.TimeoutExpired("fake cmd", 1)
self.assertEqual(str(err), "Command 'fake cmd' timed out after 1 seconds")

# timeout command string with a single-quote
err = subprocess.TimeoutExpired("fake ' cmd", 1)
self.assertEqual(str(err), 'Command "fake \' cmd" timed out after 1 seconds')

# timeout command list
err = subprocess.TimeoutExpired(["fake", "cmd"], 1)
self.assertEqual(str(err), "Command ['fake', 'cmd'] timed out after 1 seconds")

def test_preexec(self):
# DISCLAIMER: Setting environment variables is *not* a good use
# of a preexec_fn. This is merely a test.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid redundant quoting in :exc:`subprocess.TimeoutExpired` messages.
Loading