diff -r 5cae52417b9d Lib/test/support.py --- a/Lib/test/support.py Thu Jun 30 20:04:06 2011 +0200 +++ b/Lib/test/support.py Thu Jun 30 18:43:53 2011 -0400 @@ -49,7 +49,8 @@ "threading_cleanup", "reap_children", "cpython_only", "check_impl_detail", "get_attribute", "swap_item", "swap_attr", "requires_IEEE_754", "TestHandler", "Matcher", "can_symlink", "skip_unless_symlink", - "import_fresh_module", "requires_zlib", "PIPE_MAX_SIZE" + "import_fresh_module", "requires_zlib", "PIPE_MAX_SIZE", + "requires_tkinter", ] class Error(Exception): @@ -471,6 +472,16 @@ requires_zlib = unittest.skipUnless(zlib, 'requires zlib') +def requires_tkinter(gui=False): + # Skip test if _tkinter wasn't built. + import_module('_tkinter') + if gui \ + and sys.platform == 'darwin' \ + and 'DISPLAY' not in os.environ: + raise unittest.SkipTest( + "DISPLAY environment variable is required " + "to run Tkinter GUI tests") + is_jython = sys.platform.startswith('java') # Filename used for testing diff -r 5cae52417b9d Lib/test/test_tcl.py --- a/Lib/test/test_tcl.py Thu Jun 30 20:04:06 2011 +0200 +++ b/Lib/test/test_tcl.py Thu Jun 30 18:43:53 2011 -0400 @@ -5,18 +5,17 @@ import os from test import support -# Skip this test if the _tkinter module wasn't built. -_tkinter = support.import_module('_tkinter') +support.requires_tkinter() from tkinter import Tcl -from _tkinter import TclError +from _tkinter import TclError, _flatten class TkinterTest(unittest.TestCase): def testFlattenLen(self): # flatten() - self.assertRaises(TypeError, _tkinter._flatten, True) + self.assertRaises(TypeError, _flatten, True) class TclTest(unittest.TestCase): diff -r 5cae52417b9d Lib/test/test_tk.py --- a/Lib/test/test_tk.py Thu Jun 30 20:04:06 2011 +0200 +++ b/Lib/test/test_tk.py Thu Jun 30 18:43:53 2011 -0400 @@ -1,6 +1,5 @@ from test import support -# Skip test if _tkinter wasn't built. -support.import_module('_tkinter') +support.requires_tkinter(gui=True) import tkinter from tkinter.test import runtktests diff -r 5cae52417b9d Lib/test/test_ttk_guionly.py --- a/Lib/test/test_ttk_guionly.py Thu Jun 30 20:04:06 2011 +0200 +++ b/Lib/test/test_ttk_guionly.py Thu Jun 30 18:43:53 2011 -0400 @@ -2,8 +2,7 @@ import unittest from test import support -# Skip this test if _tkinter wasn't built. -support.import_module('_tkinter') +support.requires_tkinter(gui=True) from _tkinter import TclError from tkinter import ttk diff -r 5cae52417b9d Lib/test/test_ttk_textonly.py --- a/Lib/test/test_ttk_textonly.py Thu Jun 30 20:04:06 2011 +0200 +++ b/Lib/test/test_ttk_textonly.py Thu Jun 30 18:43:53 2011 -0400 @@ -1,8 +1,7 @@ import os from test import support -# Skip this test if _tkinter does not exist. -support.import_module('_tkinter') +support.requires_tkinter() from tkinter.test import runtktests