Skip to content

Commit abf589c

Browse files
committed
refactor: reorganize imports and improve error message handling in remote pdb tests
Signed-off-by: Frost Ming <[email protected]>
1 parent 045c824 commit abf589c

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

Lib/test/test_remote_pdb.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import itertools
33
import json
44
import os
5+
import pdb
56
import re
67
import signal
78
import socket
@@ -10,14 +11,25 @@
1011
import textwrap
1112
import unittest
1213
import unittest.mock
13-
from contextlib import closing, contextmanager, redirect_stdout, redirect_stderr, ExitStack
14-
from test.support import is_wasi, cpython_only, force_color, requires_subprocess, SHORT_TIMEOUT, subTests
15-
from test.support.os_helper import TESTFN, unlink
14+
from contextlib import (
15+
ExitStack,
16+
closing,
17+
contextmanager,
18+
redirect_stderr,
19+
redirect_stdout,
20+
)
21+
from pdb import _PdbClient, _PdbServer
1622
from typing import List
1723

18-
import pdb
19-
from pdb import _PdbServer, _PdbClient
20-
24+
from test.support import (
25+
SHORT_TIMEOUT,
26+
cpython_only,
27+
force_color,
28+
is_wasi,
29+
requires_subprocess,
30+
subTests,
31+
)
32+
from test.support.os_helper import TESTFN, unlink
2133

2234
if not sys.is_remote_debug_enabled():
2335
raise unittest.SkipTest('remote debugging is disabled')
@@ -1594,11 +1606,11 @@ def test_attach_to_non_existent_process(self):
15941606
with force_color(False):
15951607
result = subprocess.run([sys.executable, "-m", "pdb", "-p", "999999"], text=True, capture_output=True)
15961608
self.assertNotEqual(result.returncode, 0)
1597-
error = (
1598-
"The specified process cannot be attached to due to insufficient permissions."
1599-
if sys.platform == "darwin" else
1600-
"Cannot attach to pid 999999, please make sure that the process exists"
1601-
)
1609+
if sys.platform == "darwin":
1610+
# On MacOS, attaching to a non-existent process gives PermissionError
1611+
error = "The specified process cannot be attached to due to insufficient permissions"
1612+
else:
1613+
error = "Cannot attach to pid 999999, please make sure that the process exists"
16021614
self.assertIn(error, result.stdout)
16031615

16041616

0 commit comments

Comments
 (0)