diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -654,6 +654,7 @@ test_times = [] support.verbose = verbose # Tell tests to be moderately quiet support.use_resources = use_resources + support.regrtest_run = True # Tell tests that regrtest is is control save_modules = sys.modules.keys() def accumulate_result(test, result): diff --git a/Lib/test/support.py b/Lib/test/support.py --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -59,7 +59,7 @@ __all__ = [ "Error", "TestFailed", "ResourceDenied", "import_module", "verbose", - "use_resources", "max_memuse", "record_original_stdout", + "use_resources", "regrtest_run", "max_memuse", "record_original_stdout", "get_original_stdout", "unload", "unlink", "rmtree", "forget", "is_resource_enabled", "requires", "requires_freebsd_version", "requires_linux_version", "requires_mac_ver", "find_unused_port", @@ -214,6 +214,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 @@ -387,9 +388,8 @@ """ if resource == 'gui' and not _is_gui_available(): raise unittest.SkipTest("Cannot use the 'gui' resource") - # 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__": + # if we're not running under regrtest, accept anything + if not regrtest_run: return if not is_resource_enabled(resource): if msg is None: diff --git a/Lib/test/test_codecmaps_hk.py b/Lib/test/test_codecmaps_hk.py --- a/Lib/test/test_codecmaps_hk.py +++ b/Lib/test/test_codecmaps_hk.py @@ -17,5 +17,4 @@ support.run_unittest(__name__) if __name__ == "__main__": - support.use_resources = ['urlfetch'] test_main() diff --git a/Lib/test/test_idle.py b/Lib/test/test_idle.py --- a/Lib/test/test_idle.py +++ b/Lib/test/test_idle.py @@ -10,10 +10,5 @@ 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. - from test import support - support.use_resources = ['gui'] # use_resources is initially None import unittest unittest.main(verbosity=2, exit=False) diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py --- a/Lib/test/test_imaplib.py +++ b/Lib/test/test_imaplib.py @@ -463,5 +463,4 @@ if __name__ == "__main__": - support.use_resources = ['network'] unittest.main() diff --git a/Lib/test/test_robotparser.py b/Lib/test/test_robotparser.py --- a/Lib/test/test_robotparser.py +++ b/Lib/test/test_robotparser.py @@ -290,5 +290,4 @@ return suite if __name__=='__main__': - support.use_resources = ['network'] unittest.main() diff --git a/Lib/test/test_tk.py b/Lib/test/test_tk.py --- a/Lib/test/test_tk.py +++ b/Lib/test/test_tk.py @@ -11,15 +11,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 --git a/Lib/test/test_ttk_guionly.py b/Lib/test/test_ttk_guionly.py --- a/Lib/test/test_ttk_guionly.py +++ b/Lib/test/test_ttk_guionly.py @@ -23,13 +23,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'])) @@ -37,4 +31,4 @@ get_tk_root().destroy() if __name__ == '__main__': - test_main(enable_gui=True) + test_main()