Skip to content

Commit 21ed1e2

Browse files
gh-65784: Add support for parametrized resource wantobjects in regrtests (GH-143570)
This allows to run Tkinter tests with the specified value of tkinter.wantobjects, for example "-u wantobjects=0".
1 parent edeebe2 commit 21ed1e2

21 files changed

+46
-1
lines changed

Lib/test/libregrtest/cmdline.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@
134134
and 3.9 to test backwards compatibility. These tests
135135
may take very long to complete.
136136
137+
wantobjects - Allows to run Tkinter tests with the specified value of
138+
tkinter.wantobjects.
139+
137140
To enable all resources except one, use '-uall,-<resource>'. For
138141
example, to run all the tests except for the gui tests, give the
139142
option '-uall,-gui'.

Lib/test/libregrtest/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
# - tzdata: while needed to validate fully test_datetime, it makes
4242
# test_datetime too slow (15-20 min on some buildbots) and so is disabled by
4343
# default (see bpo-30822).
44-
RESOURCE_NAMES = ALL_RESOURCES + ('extralargefile', 'tzdata', 'xpickle')
44+
RESOURCE_NAMES = ALL_RESOURCES + ('extralargefile', 'tzdata', 'xpickle', 'wantobjects')
4545

4646

4747
# Types for types hints

Lib/test/test_tcl.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,10 @@ def test_huge_string_builtins2(self, size):
817817

818818

819819
def setUpModule():
820+
wantobjects = support.get_resource_value('wantobjects')
821+
if wantobjects is not None:
822+
unittest.enterModuleContext(
823+
support.swap_attr(tkinter, 'wantobjects', int(wantobjects)))
820824
if support.verbose:
821825
tcl = Tcl()
822826
print('patchlevel =', tcl.call('info', 'patchlevel'), flush=True)

Lib/test/test_tkinter/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@
2222

2323
def load_tests(*args):
2424
return load_package_tests(os.path.dirname(__file__), *args)
25+
26+
def setUpModule():
27+
wantobjects = support.get_resource_value('wantobjects')
28+
if wantobjects is not None:
29+
unittest.enterModuleContext(
30+
support.swap_attr(tkinter, 'wantobjects', int(wantobjects)))

Lib/test/test_tkinter/support.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
import functools
22
import tkinter
3+
import unittest
4+
from test import support
5+
6+
7+
def setUpModule():
8+
wantobjects = support.get_resource_value('wantobjects')
9+
if wantobjects is not None:
10+
unittest.enterModuleContext(
11+
support.swap_attr(tkinter, 'wantobjects', int(wantobjects)))
312

413
class AbstractTkTest:
514

@@ -10,6 +19,8 @@ def setUpClass(cls):
1019
tkinter.NoDefaultRoot()
1120
cls.root = tkinter.Tk()
1221
cls.wantobjects = cls.root.wantobjects()
22+
if support.is_resource_enabled('wantobjects'):
23+
assert cls.wantobjects == int(support.get_resource_value('wantobjects'))
1324
# De-maximize main window.
1425
# Some window managers can maximize new windows.
1526
cls.root.wm_state('normal')

Lib/test/test_tkinter/test_colorchooser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import unittest
22
import tkinter
33
from test.support import requires, swap_attr
4+
from test.test_tkinter.support import setUpModule # noqa: F401
45
from test.test_tkinter.support import AbstractDefaultRootTest, AbstractTkTest
56
from tkinter import colorchooser
67
from tkinter.colorchooser import askcolor

Lib/test/test_tkinter/test_font.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import tkinter
44
from tkinter import font
55
from test.support import requires, gc_collect, ALWAYS_EQ
6+
from test.test_tkinter.support import setUpModule # noqa: F401
67
from test.test_tkinter.support import AbstractTkTest, AbstractDefaultRootTest
78

89
requires('gui')

Lib/test/test_tkinter/test_geometry_managers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from tkinter import TclError
55
from test.support import requires
66

7+
from test.test_tkinter.support import setUpModule # noqa: F401
78
from test.test_tkinter.support import pixels_conv
89
from test.test_tkinter.widget_tests import AbstractWidgetTest
910

Lib/test/test_tkinter/test_images.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import tkinter
44
from test import support
55
from test.support import os_helper
6+
from test.test_tkinter.support import setUpModule # noqa: F401
67
from test.test_tkinter.support import AbstractTkTest, AbstractDefaultRootTest, requires_tk
78

89
support.requires('gui')

Lib/test/test_tkinter/test_loadtk.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import unittest
44
import test.support as test_support
55
from test.support import os_helper
6+
from test.test_tkinter.support import setUpModule # noqa: F401
67
from tkinter import Tcl, TclError
78

89
test_support.requires('gui')

0 commit comments

Comments
 (0)