Skip to content

Commit 3eec508

Browse files
committed
Fix tests requiring tkinter
1 parent 58f4da0 commit 3eec508

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

Lib/test/test_pyrepl/test_pyrepl.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
import pty
5454
except ImportError:
5555
pty = None
56+
try:
57+
import tkinter
58+
except ImportError:
59+
tkinter = None
5660

5761

5862
class ReplTestCase(TestCase):
@@ -1551,7 +1555,8 @@ def test_no_side_effects(self):
15511555
with (captured_stdout() as out,
15521556
captured_stderr() as err,
15531557
self._capture_audit_events() as audit_events,
1554-
patch("tkinter._tkinter.create") as tk_mock,
1558+
(patch("tkinter._tkinter.create") if tkinter
1559+
else contextlib.nullcontext()) as tk_mock,
15551560
warnings.catch_warnings(action="ignore"),
15561561
patch.dict(sys.modules)):
15571562
completer._maybe_import_module(modname)
@@ -1562,7 +1567,8 @@ def test_no_side_effects(self):
15621567
# 2. spawn any subprocess (eg. webbrowser.open)
15631568
self.assertNotIn("subprocess.Popen", audit_events)
15641569
# 3. launch a Tk window
1565-
tk_mock.assert_not_called()
1570+
if tk_mock is not None:
1571+
tk_mock.assert_not_called()
15661572

15671573

15681574
class TestHardcodedSubmodules(TestCase):

0 commit comments

Comments
 (0)