Skip to content

Commit 5125a0d

Browse files
loic-simonpablogsal
authored andcommitted
Fix tests requiring tkinter
1 parent 17599ed commit 5125a0d

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
@@ -59,6 +59,10 @@
5959
import readline as readline_module
6060
except ImportError:
6161
readline_module = None
62+
try:
63+
import tkinter
64+
except ImportError:
65+
tkinter = None
6266

6367

6468
class ReplTestCase(TestCase):
@@ -1644,7 +1648,8 @@ def test_no_side_effects(self):
16441648
with (captured_stdout() as out,
16451649
captured_stderr() as err,
16461650
self._capture_audit_events() as audit_events,
1647-
patch("tkinter._tkinter.create") as tk_mock,
1651+
(patch("tkinter._tkinter.create") if tkinter
1652+
else contextlib.nullcontext()) as tk_mock,
16481653
warnings.catch_warnings(action="ignore"),
16491654
patch.dict(sys.modules)):
16501655
completer._maybe_import_module(modname)
@@ -1655,7 +1660,8 @@ def test_no_side_effects(self):
16551660
# 2. spawn any subprocess (eg. webbrowser.open)
16561661
self.assertNotIn("subprocess.Popen", audit_events)
16571662
# 3. launch a Tk window
1658-
tk_mock.assert_not_called()
1663+
if tk_mock is not None:
1664+
tk_mock.assert_not_called()
16591665

16601666

16611667
class TestHardcodedSubmodules(TestCase):

0 commit comments

Comments
 (0)