@@ -26,20 +26,19 @@ Once test_xyy is written, the following should go at the end of xyy.py,
2626with xyz (lowercased) added after 'test_'.
2727---
2828if __name__ == "__main__":
29- from test import support; support.use_resources = ['gui']
3029 import unittest
3130 unittest.main('idlelib.idle_test.test_', verbosity=2, exit=False)
3231---
3332
3433
35342. Gui Tests
3635
37- Gui tests need 'requires' and 'use_resources' from test.support
38- ( test.test_support in 2.7). A test is a gui test if it creates a Tk root or
39- master object either directly or indirectly by instantiating a tkinter or
40- idle class. For the benefit of buildbot machines that do not have a graphics
41- screen , gui tests must be 'guarded' by "requires('gui')" in a setUp
42- function or method. This will typically be setUpClass.
36+ Gui tests need 'requires' from test.support (test.test_support in 2.7). A
37+ test is a gui test if it creates a Tk root or master object either directly
38+ or indirectly by instantiating a tkinter or idle class. For the benefit of
39+ test processes that either have no graphical environment available or are not
40+ allowed to use it , gui tests must be 'guarded' by "requires('gui')" in a
41+ setUp function or method. This will typically be setUpClass.
4342
4443To avoid interfering with other gui tests, all gui objects must be destroyed
4544and deleted by the end of the test. If a widget, such as a Tk root, is created
@@ -57,11 +56,17 @@ and class attributes, also delete the widget.
5756 del cls.root
5857---
5958
60- Support.requires('gui') returns true if it is either called in a main module
61- (which never happens on buildbots) or if use_resources contains 'gui'.
62- Use_resources is set by test.regrtest but not by unittest. So when running
63- tests in another module with unittest, we set it ourselves, as in the xyz.py
64- template above.
59+ Support.requires('gui') causes the test(s) it guards to be skipped if any of
60+ a few conditions are met:
61+ - The tests are being run by regrtest.py, and it was started without
62+ enabling the "gui" resource with the "-u" command line option.
63+ - The tests are being run on Windows by a service that is not allowed to
64+ interact with the graphical environment.
65+ - The tests are being run on Mac OSX in a process that cannot make a window
66+ manager connection.
67+ - tkinter.Tk cannot be successfully instantiated for some reason.
68+ - test.support.use_resources has been set by something other than
69+ regrtest.py and does not contain "gui".
6570
6671Since non-gui tests always run, but gui tests only sometimes, tests of non-gui
6772operations should best avoid needing a gui. Methods that make incidental use of
@@ -88,8 +93,8 @@ python -m idlelib.idle_test.test_xyz
8893
8994To run all idle_test/test_*.py tests, either interactively
9095('>>>', with unittest imported) or from a command line, use one of the
91- following. (Notes: unittest does not run gui tests; in 2.7, 'test ' (with the
92- space) is 'test.regrtest '; where present, -v and -ugui can be omitted.)
96+ following. (Notes: in 2.7, 'test ' (with the space) is 'test.regrtest ';
97+ where present, -v and -ugui can be omitted.)
9398
9499>>> unittest.main('idlelib.idle_test', verbosity=2, exit=False)
95100python -m unittest -v idlelib.idle_test
@@ -98,13 +103,13 @@ python -m test.test_idle
98103
99104The idle tests are 'discovered' by idlelib.idle_test.__init__.load_tests,
100105which is also imported into test.test_idle. Normally, neither file should be
101- changed when working on individual test modules. The third command runs runs
106+ changed when working on individual test modules. The third command runs
102107unittest indirectly through regrtest. The same happens when the entire test
103108suite is run with 'python -m test'. So that command must work for buildbots
104109to stay green. Idle tests must not disturb the environment in a way that
105110makes other tests fail (issue 18081).
106111
107112To run an individual Testcase or test method, extend the dotted name given to
108- unittest on the command line. (But gui tests will not this way.)
113+ unittest on the command line.
109114
110115python -m unittest -v idlelib.idle_test.test_xyz.Test_case.test_meth
0 commit comments