diff -r 5d0783376c88 Lib/idlelib/FormatParagraph.py --- a/Lib/idlelib/FormatParagraph.py Mon May 05 07:35:29 2014 -0700 +++ b/Lib/idlelib/FormatParagraph.py Wed May 07 12:25:29 2014 -0500 @@ -188,7 +188,6 @@ return m.group(1) if __name__ == "__main__": - from test import support; support.use_resources = ['gui'] import unittest unittest.main('idlelib.idle_test.test_formatparagraph', verbosity=2, exit=False) diff -r 5d0783376c88 Lib/idlelib/IdleHistory.py --- a/Lib/idlelib/IdleHistory.py Mon May 05 07:35:29 2014 -0700 +++ b/Lib/idlelib/IdleHistory.py Wed May 07 12:25:29 2014 -0500 @@ -100,7 +100,5 @@ self.prefix = None if __name__ == "__main__": - from test import support - support.use_resources = ['gui'] from unittest import main main('idlelib.idle_test.test_idlehistory', verbosity=2, exit=False) diff -r 5d0783376c88 Lib/idlelib/SearchEngine.py --- a/Lib/idlelib/SearchEngine.py Mon May 05 07:35:29 2014 -0700 +++ b/Lib/idlelib/SearchEngine.py Wed May 07 12:25:29 2014 -0500 @@ -229,6 +229,5 @@ return line, col if __name__ == "__main__": - from test import support; support.use_resources = ['gui'] import unittest unittest.main('idlelib.idle_test.test_searchengine', verbosity=2, exit=False) diff -r 5d0783376c88 Lib/idlelib/idle_test/README.txt --- a/Lib/idlelib/idle_test/README.txt Mon May 05 07:35:29 2014 -0700 +++ b/Lib/idlelib/idle_test/README.txt Wed May 07 12:25:29 2014 -0500 @@ -26,7 +26,6 @@ with xyz (lowercased) added after 'test_'. --- if __name__ == "__main__": - from test import support; support.use_resources = ['gui'] import unittest unittest.main('idlelib.idle_test.test_', verbosity=2, exit=False) --- @@ -34,12 +33,12 @@ 2. Gui Tests -Gui tests need 'requires' and 'use_resources' from test.support -(test.test_support in 2.7). A test is a gui test if it creates a Tk root or -master object either directly or indirectly by instantiating a tkinter or -idle class. For the benefit of buildbot machines that do not have a graphics -screen, gui tests must be 'guarded' by "requires('gui')" in a setUp -function or method. This will typically be setUpClass. +Gui tests need 'requires' from test.support (test.test_support in 2.7). A +test is a gui test if it creates a Tk root or master object either directly +or indirectly by instantiating a tkinter or idle class. For the benefit of +test processes that either have no graphical environment available or are not +allowed to use it, gui tests must be 'guarded' by "requires('gui')" in a +setUp function or method. This will typically be setUpClass. To avoid interfering with other gui tests, all gui objects must be destroyed and deleted by the end of the test. If a widget, such as a Tk root, is created @@ -57,11 +56,17 @@ del cls.root --- -Support.requires('gui') returns true if it is either called in a main module -(which never happens on buildbots) or if use_resources contains 'gui'. -Use_resources is set by test.regrtest but not by unittest. So when running -tests in another module with unittest, we set it ourselves, as in the xyz.py -template above. +Support.requires('gui') causes the test(s) it guards to be skipped if any of +a few conditions are met: + - The tests are being run by regrtest.py, and it was started without + enabling the "gui" resource with the "-u" command line option. + - The tests are being run on Windows by a service that is not allowed to + interact with the graphical environment. + - The tests are being run on Mac OSX in a process that cannot make a window + manager connection. + - tkinter.Tk cannot be successfully instantiated for some reason. + - test.support.use_resources has been set by something other than + regrtest.py and does not contain "gui". Since non-gui tests always run, but gui tests only sometimes, tests of non-gui operations should best avoid needing a gui. Methods that make incidental use of @@ -88,8 +93,8 @@ To run all idle_test/test_*.py tests, either interactively ('>>>', with unittest imported) or from a command line, use one of the -following. (Notes: unittest does not run gui tests; in 2.7, 'test ' (with the -space) is 'test.regrtest '; where present, -v and -ugui can be omitted.) +following. (Notes: in 2.7, 'test ' (with the space) is 'test.regrtest '; +where present, -v and -ugui can be omitted.) >>> unittest.main('idlelib.idle_test', verbosity=2, exit=False) python -m unittest -v idlelib.idle_test @@ -98,13 +103,13 @@ The idle tests are 'discovered' by idlelib.idle_test.__init__.load_tests, which is also imported into test.test_idle. Normally, neither file should be -changed when working on individual test modules. The third command runs runs +changed when working on individual test modules. The third command runs unittest indirectly through regrtest. The same happens when the entire test suite is run with 'python -m test'. So that command must work for buildbots to stay green. Idle tests must not disturb the environment in a way that makes other tests fail (issue 18081). To run an individual Testcase or test method, extend the dotted name given to -unittest on the command line. (But gui tests will not this way.) +unittest on the command line. python -m unittest -v idlelib.idle_test.test_xyz.Test_case.test_meth diff -r 5d0783376c88 Lib/test/regrtest.py --- a/Lib/test/regrtest.py Mon May 05 07:35:29 2014 -0700 +++ b/Lib/test/regrtest.py Wed May 07 12:25:29 2014 -0500 @@ -641,6 +641,7 @@ test_times = [] support.verbose = ns.verbose # Tell tests to be moderately quiet support.use_resources = ns.use_resources + support.regrtest_run = True # Make known that regrtest is in control save_modules = sys.modules.keys() def accumulate_result(test, result): diff -r 5d0783376c88 Lib/test/support/__init__.py --- a/Lib/test/support/__init__.py Mon May 05 07:35:29 2014 -0700 +++ b/Lib/test/support/__init__.py Wed May 07 12:25:29 2014 -0500 @@ -64,6 +64,7 @@ __all__ = [ # globals "PIPE_MAX_SIZE", "verbose", "max_memuse", "use_resources", "failfast", + "regrtest_run", # exceptions "Error", "TestFailed", "ResourceDenied", # imports @@ -249,6 +250,7 @@ verbose = 1 # Flag set to 0 by regrtest.py use_resources = None # Flag set to [] by regrtest.py +regrtest_run = False # Flag set to True by regrtest.py max_memuse = 0 # Disable bigmem tests (they will still be run with # small sizes, to make sure they work.) real_max_memuse = 0 @@ -454,23 +456,19 @@ return _is_gui_available.result def is_resource_enabled(resource): - """Test whether a resource is enabled. Known resources are set by - regrtest.py.""" + """Test whether a resource is enabled. + + Known resources are set by regrtest.py. If not running under regrtest.py, + all resources are assumed enabled unless use_resources has been set. + """ + if not regrtest_run and use_resources is None: + return True return use_resources is not None and resource in use_resources def requires(resource, msg=None): - """Raise ResourceDenied if the specified resource is not available. - - If the caller's module is __main__ then automatically return True. The - possibility of False being returned occurs when regrtest.py is - executing. - """ + """Raise ResourceDenied if the specified resource is not available.""" if resource == 'gui' and not _is_gui_available(): raise ResourceDenied(_is_gui_available.reason) - # see if the caller's module is __main__ - if so, treat as if - # the resource was set - if sys._getframe(1).f_globals.get("__name__") == "__main__": - return if not is_resource_enabled(resource): if msg is None: msg = "Use of the %r resource not enabled" % resource diff -r 5d0783376c88 Lib/test/test_codecmaps_hk.py --- a/Lib/test/test_codecmaps_hk.py Mon May 05 07:35:29 2014 -0700 +++ b/Lib/test/test_codecmaps_hk.py Wed May 07 12:25:29 2014 -0500 @@ -16,5 +16,4 @@ support.run_unittest(__name__) if __name__ == "__main__": - support.use_resources = ['urlfetch'] test_main() diff -r 5d0783376c88 Lib/test/test_decimal.py --- a/Lib/test/test_decimal.py Mon May 05 07:35:29 2014 -0700 +++ b/Lib/test/test_decimal.py Wed May 07 12:25:29 2014 -0500 @@ -5556,7 +5556,7 @@ all_tests.insert(1, SignatureTest) -def test_main(arith=False, verbose=None, todo_tests=None, debug=None): +def test_main(arith=None, verbose=None, todo_tests=None, debug=None): """ Execute the tests. Runs all arithmetic tests if arith is True or if the "decimal" resource @@ -5566,7 +5566,7 @@ init(C) init(P) global TEST_ALL, DEBUG - TEST_ALL = arith or is_resource_enabled('decimal') + TEST_ALL = arith if arith is not None else is_resource_enabled('decimal') DEBUG = debug if todo_tests is None: diff -r 5d0783376c88 Lib/test/test_idle.py --- a/Lib/test/test_idle.py Mon May 05 07:35:29 2014 -0700 +++ b/Lib/test/test_idle.py Wed May 07 12:25:29 2014 -0500 @@ -13,8 +13,4 @@ load_tests = idletest.load_tests if __name__ == '__main__': - # Until unittest supports resources, we emulate regrtest's -ugui - # so loaded tests run the same as if textually present here. - # If any Idle test ever needs another resource, add it to the list. - support.use_resources = ['gui'] # use_resources is initially None unittest.main(verbosity=2, exit=False) diff -r 5d0783376c88 Lib/test/test_imaplib.py --- a/Lib/test/test_imaplib.py Mon May 05 07:35:29 2014 -0700 +++ b/Lib/test/test_imaplib.py Wed May 07 12:25:29 2014 -0500 @@ -501,5 +501,4 @@ if __name__ == "__main__": - support.use_resources = ['network'] unittest.main() diff -r 5d0783376c88 Lib/test/test_robotparser.py --- a/Lib/test/test_robotparser.py Mon May 05 07:35:29 2014 -0700 +++ b/Lib/test/test_robotparser.py Wed May 07 12:25:29 2014 -0500 @@ -291,5 +291,4 @@ return suite if __name__=='__main__': - support.use_resources = ['network'] unittest.main() diff -r 5d0783376c88 Lib/test/test_tk.py --- a/Lib/test/test_tk.py Mon May 05 07:35:29 2014 -0700 +++ b/Lib/test/test_tk.py Wed May 07 12:25:29 2014 -0500 @@ -10,15 +10,9 @@ from tkinter.test import runtktests -def test_main(enable_gui=False): - if enable_gui: - if support.use_resources is None: - support.use_resources = ['gui'] - elif 'gui' not in support.use_resources: - support.use_resources.append('gui') - +def test_main(): support.run_unittest( *runtktests.get_tests(text=False, packages=['test_tkinter'])) if __name__ == '__main__': - test_main(enable_gui=True) + test_main() diff -r 5d0783376c88 Lib/test/test_ttk_guionly.py --- a/Lib/test/test_ttk_guionly.py Mon May 05 07:35:29 2014 -0700 +++ b/Lib/test/test_ttk_guionly.py Wed May 07 12:25:29 2014 -0500 @@ -22,13 +22,7 @@ # assuming ttk is not available raise unittest.SkipTest("ttk not available: %s" % msg) -def test_main(enable_gui=False): - if enable_gui: - if support.use_resources is None: - support.use_resources = ['gui'] - elif 'gui' not in support.use_resources: - support.use_resources.append('gui') - +def test_main(): try: support.run_unittest( *runtktests.get_tests(text=False, packages=['test_ttk'])) @@ -36,4 +30,4 @@ get_tk_root().destroy() if __name__ == '__main__': - test_main(enable_gui=True) + test_main() diff -r 5d0783376c88 Lib/tkinter/test/runtktests.py --- a/Lib/tkinter/test/runtktests.py Mon May 05 07:35:29 2014 -0700 +++ b/Lib/tkinter/test/runtktests.py Wed May 07 12:25:29 2014 -0500 @@ -68,5 +68,4 @@ yield test if __name__ == "__main__": - test.support.use_resources = ['gui'] test.support.run_unittest(*get_tests())