Skip to content

Commit a144037

Browse files
[3.12] gh-61698: Use launchctl to detect macOS window manager in tests (GH-118390) (#125393)
(cherry picked from commit ce740d4) Co-authored-by: Erlend E. Aasland <[email protected]>
1 parent afddaeb commit a144037

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

Lib/test/support/__init__.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -250,22 +250,16 @@ class USEROBJECTFLAGS(ctypes.Structure):
250250
# process not running under the same user id as the current console
251251
# user. To avoid that, raise an exception if the window manager
252252
# connection is not available.
253-
from ctypes import cdll, c_int, pointer, Structure
254-
from ctypes.util import find_library
255-
256-
app_services = cdll.LoadLibrary(find_library("ApplicationServices"))
257-
258-
if app_services.CGMainDisplayID() == 0:
259-
reason = "gui tests cannot run without OS X window manager"
253+
import subprocess
254+
try:
255+
rc = subprocess.run(["launchctl", "managername"],
256+
capture_output=True, check=True)
257+
managername = rc.stdout.decode("utf-8").strip()
258+
except subprocess.CalledProcessError:
259+
reason = "unable to detect macOS launchd job manager"
260260
else:
261-
class ProcessSerialNumber(Structure):
262-
_fields_ = [("highLongOfPSN", c_int),
263-
("lowLongOfPSN", c_int)]
264-
psn = ProcessSerialNumber()
265-
psn_p = pointer(psn)
266-
if ( (app_services.GetCurrentProcess(psn_p) < 0) or
267-
(app_services.SetFrontProcess(psn_p) < 0) ):
268-
reason = "cannot run without OS X gui process"
261+
if managername != "Aqua":
262+
reason = f"{managername=} -- can only run in a macOS GUI session"
269263

270264
# check on every platform whether tkinter can actually do anything
271265
if not reason:

0 commit comments

Comments
 (0)