diff -r 00d09afb57ca Lib/test/test___all__.py --- a/Lib/test/test___all__.py Fri Dec 20 22:14:03 2013 +1000 +++ b/Lib/test/test___all__.py Fri Dec 20 11:39:13 2013 -0600 @@ -112,6 +112,10 @@ ignored) print('Following modules failed to be imported:', failed_imports) +def tearDownModule(): + # Remove tkinter's changes to os.environ to avoid warnings from regrtest + from tkinter._fix import unfix_environ + unfix_environ() if __name__ == "__main__": unittest.main() diff -r 00d09afb57ca Lib/test/test_idle.py --- a/Lib/test/test_idle.py Fri Dec 20 22:14:03 2013 +1000 +++ b/Lib/test/test_idle.py Fri Dec 20 11:39:13 2013 -0600 @@ -23,6 +23,11 @@ # load_tests() if it finds it. (Unittest.main does the same.) load_tests = idletest.load_tests +def tearDownModule(): + # Remove changes to os.environ to avoid warnings from regrtest + from tkinter._fix import unfix_environ + unfix_environ() + if __name__ == '__main__': # Until unittest supports resources, we emulate regrtest's -ugui # so loaded tests run the same as if textually present here. diff -r 00d09afb57ca Lib/test/test_tcl.py --- a/Lib/test/test_tcl.py Fri Dec 20 22:14:03 2013 +1000 +++ b/Lib/test/test_tcl.py Fri Dec 20 11:39:13 2013 -0600 @@ -9,9 +9,6 @@ # Skip this test if the _tkinter module wasn't built. _tkinter = support.import_module('_tkinter') -# Make sure tkinter._fix runs to set up the environment -support.import_fresh_module('tkinter') - from tkinter import Tcl from _tkinter import TclError @@ -273,9 +270,11 @@ tcl = Tcl() print('patchlevel =', tcl.call('info', 'patchlevel')) +def tearDownModule(): + # Remove changes to os.environ to avoid warnings from regrtest + from tkinter._fix import unfix_environ + unfix_environ() -def test_main(): - support.run_unittest(TclTest, TkinterTest, BigmemTclTest) if __name__ == "__main__": - test_main() + unittest.main() diff -r 00d09afb57ca Lib/test/test_tk.py --- a/Lib/test/test_tk.py Fri Dec 20 22:14:03 2013 +1000 +++ b/Lib/test/test_tk.py Fri Dec 20 11:39:13 2013 -0600 @@ -2,9 +2,6 @@ # Skip test if _tkinter wasn't built. support.import_module('_tkinter') -# Make sure tkinter._fix runs to set up the environment -support.import_fresh_module('tkinter') - # Skip test if tk cannot be initialized. from tkinter.test.support import check_tk_availability check_tk_availability() @@ -21,5 +18,9 @@ support.run_unittest( *runtktests.get_tests(text=False, packages=['test_tkinter'])) + # Remove changes to os.environ to avoid warnings from regrtest + from tkinter._fix import unfix_environ + unfix_environ() + if __name__ == '__main__': test_main(enable_gui=True) diff -r 00d09afb57ca Lib/test/test_ttk_guionly.py --- a/Lib/test/test_ttk_guionly.py Fri Dec 20 22:14:03 2013 +1000 +++ b/Lib/test/test_ttk_guionly.py Fri Dec 20 11:39:13 2013 -0600 @@ -5,9 +5,6 @@ # Skip this test if _tkinter wasn't built. support.import_module('_tkinter') -# Make sure tkinter._fix runs to set up the environment -support.import_fresh_module('tkinter') - # Skip test if tk cannot be initialized. from tkinter.test.support import check_tk_availability check_tk_availability() @@ -34,7 +31,12 @@ support.run_unittest( *runtktests.get_tests(text=False, packages=['test_ttk'])) finally: + # don't leave a window hanging around get_tk_root().destroy() + # Remove changes to os.environ to avoid warnings from regrtest + from tkinter._fix import unfix_environ + unfix_environ() + if __name__ == '__main__': test_main(enable_gui=True) diff -r 00d09afb57ca Lib/test/test_ttk_textonly.py --- a/Lib/test/test_ttk_textonly.py Fri Dec 20 22:14:03 2013 +1000 +++ b/Lib/test/test_ttk_textonly.py Fri Dec 20 11:39:13 2013 -0600 @@ -4,14 +4,15 @@ # Skip this test if _tkinter does not exist. support.import_module('_tkinter') -# Make sure tkinter._fix runs to set up the environment -support.import_fresh_module('tkinter') - from tkinter.test import runtktests def test_main(): support.run_unittest( *runtktests.get_tests(gui=False, packages=['test_ttk'])) + # Remove changes to os.environ to avoid warnings from regrtest + from tkinter._fix import unfix_environ + unfix_environ() + if __name__ == '__main__': test_main() diff -r 00d09afb57ca Lib/tkinter/_fix.py --- a/Lib/tkinter/_fix.py Fri Dec 20 22:14:03 2013 +1000 +++ b/Lib/tkinter/_fix.py Fri Dec 20 11:39:13 2013 -0600 @@ -46,6 +46,9 @@ s = "\\" + s[3:] return s +orig_environ = os.environ.copy() + +# Add (TCL|TK|TIX)_LIBRARY vars to os.environ so init.tcl can be found prefix = os.path.join(sys.base_prefix,"tcl") if not os.path.exists(prefix): # devdir/../tcltk/lib @@ -76,3 +79,14 @@ tixdir = os.path.join(prefix,name) if os.path.isdir(tixdir): os.environ["TIX_LIBRARY"] = tixdir + +def unfix_environ(orig_environ=orig_environ): + # Use this function to undo the changes made by fix_environ() + for var in ['TCL_LIBRARY', 'TK_LIBRARY', 'TIX_LIBRARY']: + if var not in orig_environ: + os.environ.pop(var, None) + + # Make sure the environment is fixed again next time tkinter is imported + del sys.modules['tkinter._fix'] + +del orig_environ