Skip to content

Commit 8ba6469

Browse files
Do not check the focus on Windows if the application did not get it
On the Windows CI runners "focus -force" has no effect, because SetForegroundWindow() is refused for a background process.
1 parent a89df13 commit 8ba6469

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎Lib/test/test_tkinter/test_simpledialog.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
import unittest
23
import tkinter
34
from tkinter import messagebox, ttk
@@ -256,11 +257,15 @@ def test_go_foreign_grab(self):
256257
tk.call('update')
257258
tk.call('grab', 'set', '.foreign')
258259
tk.call('focus', '-force', '.foreign')
260+
# On Windows the application may not get the focus, and then "focus"
261+
# returns an empty string.
262+
has_focus = tk.call('focus') == '.foreign'
259263
d = self.create()
260264
d.root.after(1, lambda: d._buttons[0].invoke())
261265
self.assertEqual(d.go(), 0)
262266
self.assertEqual(tk.call('grab', 'current', self.root._w), '.foreign')
263-
self.assertEqual(tk.call('focus'), '.foreign')
267+
if sys.platform != 'win32' or has_focus:
268+
self.assertEqual(tk.call('focus'), '.foreign')
264269

265270

266271
class DialogTest(AbstractDialogTest, unittest.TestCase):

0 commit comments

Comments
 (0)