Skip to content

Commit 6fdb9f1

Browse files
[3.13] gh-65784: Add support for parametrized resource wantobjects in regrtests (GH-143570) (GH-143914)
This allows to run Tkinter tests with the specified value of tkinter.wantobjects, for example "-u wantobjects=0". (cherry picked from commit 21ed1e2) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent 201e819 commit 6fdb9f1

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
@@ -124,6 +124,9 @@
124124
and 3.9 to test backwards compatibility. These tests
125125
may take very long to complete.
126126
127+
wantobjects - Allows to run Tkinter tests with the specified value of
128+
tkinter.wantobjects.
129+
127130
To enable all resources except one, use '-uall,-<resource>'. For
128131
example, to run all the tests except for the gui tests, give the
129132
option '-uall,-gui'.

Lib/test/libregrtest/utils.py

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

4747

4848
# 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
@@ -2,6 +2,7 @@
22
import tkinter
33
from tkinter import font
44
from test.support import requires, gc_collect, ALWAYS_EQ
5+
from test.test_tkinter.support import setUpModule # noqa: F401
56
from test.test_tkinter.support import AbstractTkTest, AbstractDefaultRootTest
67

78
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
@@ -2,6 +2,7 @@
22
import tkinter
33
from test import support
44
from test.support import os_helper
5+
from test.test_tkinter.support import setUpModule # noqa: F401
56
from test.test_tkinter.support import AbstractTkTest, AbstractDefaultRootTest, requires_tk
67

78
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)