Skip to content

test_tkinter failing on MacOS #128846

Description

@smontanaro

Bug report

Bug description:

test_tkinter is failing on MacOS (Sequoia 15.2, M1 MacBook Pro, in my case). It was working fine yesterday, so without delving into this too deeply, I'm going to suggest this change overnight broke things. See attached log

commit da8825ea95a7096bb4f933d33b212a94ade10f6e
Author: Zhikang Yan <2951256653@qq.com>
Date:   Mon Jan 13 23:54:46 2025 +0800

    gh-128562: Fix generation of the tkinter widget names (GH-128604)
    
    There were possible conflicts if the widget class name ends with a digit.

@Xiaokang2022

(FWIW, test_ttk is failing for me on 3.13, but not main. It appears to be a different problem.)

test_tkinter.log

CPython versions tested on:

CPython main branch, 3.13

Operating systems tested on:

macOS

Linked PRs

Activity

  1. zanieb commented on Jan 14, 2025

    @zanieb
    Contributor

    The referenced commit is from #128604 / #128562

  2. zanieb commented on Jan 14, 2025

    @zanieb
    Contributor

    I can reproduce this on main / f7ceb31 but reverting da8825e does not resolve the failure.

  3. zanieb commented on Jan 14, 2025

    @zanieb
    Contributor

    I also reproduced this on an arbitrary older commit 2fcdc84 (and then b2ac70a)

    If I go back to ce740d4, which I need to run the GUI tests on my machine, I get a bunch of failures — including what looks like the failures reported here. @smontanaro I don't know if it makes sense that these tests worked yesterday.

  4. zanieb commented on Jan 14, 2025

    @zanieb
    Contributor

    It looks like this is caused by using tk 9.0+, at least on my machine, Brew upgraded to a new version.

    You can confirm with

    ❯ ./python.exe -c 'import tkinter; tcl = tkinter.Tcl(); print(tcl.call("info", "patchlevel"))'
    9.0.1
    

    In which case, this is part of

    I don't think the tests are expected to pass with tk 9 yet.

  5. smontanaro commented on Jan 14, 2025

    @smontanaro
    ContributorAuthor

    Hmmm... This might turn out to be pilot error. I have a config file in my personal build environment which gets Tcl/Tk libs from my Conda env:

    TCLTK_CFLAGS=-I/Users/skip/miniconda3/envs/python312/include
    TCLTK_LIBS='-L/Users/skip/miniconda3/envs/python312/lib -Wl,-rpath,/Users/skip/miniconda3/envs/python312/lib -ltk8.6 -ltkstub8.6 -ltcl8.6 -ltclstub8.6'
    

    Somehow that was dropped from a command recalled from my bash history, so I was picking up 9.0.1. Now that I've corrected my commands, my build on main works and yields the expected version:

    % ./python.exe -c 'import tkinter; tcl = tkinter.Tcl(); print(tcl.call("info", "patchlevel"))'
    8.6.13
    

    I've yet to pull in the correct command on my 3.13 Terminal window, so it still yields the later version:

    % ./python.exe -c 'import tkinter; tcl = tkinter.Tcl(); print(tcl.call("info", "patchlevel"))'
    9.0.1
    

    Would it be worthwhile running this bit of code in the test suite, then skipping the tests if Tcl/Tk v9 was found?

  6. zanieb commented on Jan 14, 2025

    @zanieb
    Contributor

    That seems reasonable to me, but I'd be curious to hear from someone that's a stakeholder for that topic.

  7. sobolevn commented on Jan 15, 2025

    @sobolevn
    Member
  8. Xiaokang2022 commented on Jan 15, 2025

    @Xiaokang2022
    Contributor

    This doesn't seem to be the cause of my commit, which passed macOS-related tests.

  9. terryjreedy commented on Jan 15, 2025

    @terryjreedy
    Member

    @serhiy-storchaka is the tkinter expert, not me. I would like to be able to use 9.0, but I don't know where that stands now.

  10. warsaw commented on Jul 9, 2026

    @warsaw
    Member

    FWIW, I see test_tkinter blocking unrelated 3.13 backports, pretty consistently. On a local 3.13 branch, both test_tkinter and test_ttk fail for me consistently too.

    % brew info tcl-tk
    ...
    ==> Installed Versions
    tcl-tk ✔ 9.0.3 (3,158 files, 40MB) [Linked]
    

    For me, they pass on all newer branches.

  11. serhiy-storchaka commented on Jul 9, 2026

    @serhiy-storchaka
    Member

    test_wm_iconbitmap has separate issue #146531. Other failures are not related to it.

    The original report was 1.5 years ago, there were many changes in tests since then, especially in last month. Please check if the originally reported failure still reproduced (besides test_wm_iconbitmap). I have no Mac, so my capabilities to address Mac-only issues are limited.

  12. warsaw commented on Jul 9, 2026

    @warsaw
    Member

    @hugovk "fixed" the timeout, but I still see two actual failures:

    0:01:55 load avg: 6.32 running (1): test_ttk (31.4 sec)
    0:02:25 load avg: 5.86 running (1): test_ttk (1 min 1 sec)
    0:02:55 load avg: 5.26 running (1): test_ttk (1 min 31 sec)
    0:03:05 load avg: 4.90 [4/4/2] test_ttk failed (9 failures) (1 min 40 sec)
    Re-running test_ttk in verbose mode (matching: test_configure_image, test_configure_custom_copy, test_element_create_from_errors, test_configure_image, test_configure_image, test_virtual_event, test_configure_image, test_configure_image, test_configure_image)
    test_configure_image (test.test_ttk.test_extensions.OptionMenuTest.test_configure_image) ... FAIL
    test_configure_custom_copy (test.test_ttk.test_style.StyleTest.test_configure_custom_copy) ...
      test_configure_custom_copy (test.test_ttk.test_style.StyleTest.test_configure_custom_copy) (theme='aqua', name='.') ... FAIL
    test_element_create_from_errors (test.test_ttk.test_style.StyleTest.test_element_create_from_errors) ... FAIL
    test_configure_image (test.test_ttk.test_widgets.ButtonTest.test_configure_image) ... FAIL
    test_configure_image (test.test_ttk.test_widgets.CheckbuttonTest.test_configure_image) ... FAIL
    test_virtual_event (test.test_ttk.test_widgets.ComboboxTest.test_virtual_event) ... FAIL
    test_configure_image (test.test_ttk.test_widgets.LabelTest.test_configure_image) ... FAIL
    test_configure_image (test.test_ttk.test_widgets.MenubuttonTest.test_configure_image) ... FAIL
    test_configure_image (test.test_ttk.test_widgets.RadiobuttonTest.test_configure_image) ... FAIL
    
    ======================================================================
    FAIL: test_configure_image (test.test_ttk.test_extensions.OptionMenuTest.test_configure_image)
    ----------------------------------------------------------------------
    _tkinter.TclError: image "spam" does not exist
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/Users/barry/projects/python/3.13/Lib/test/test_tkinter/widget_tests.py", line 376, in test_configure_image
        self.checkImageParam(widget, 'image')
        ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
      File "/Users/barry/projects/python/3.13/Lib/test/test_ttk/test_widgets.py", line 185, in checkImageParam
        self.checkInvalidParam(widget, name, 'spam',
        ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
                errmsg='image "spam" doesn\'t exist')
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/barry/projects/python/3.13/Lib/test/test_tkinter/widget_tests.py", line 80, in checkInvalidParam
        with self.assertRaisesRegex(tkinter.TclError, errmsg or ''):
             ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    AssertionError: "\Aimage "spam" doesn't exist\Z" does not match "image "spam" does not exist"
    
    ======================================================================
    FAIL: test_configure_custom_copy (test.test_ttk.test_style.StyleTest.test_configure_custom_copy) (theme='aqua', name='.')
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/Users/barry/projects/python/3.13/Lib/test/test_ttk/test_style.py", line 164, in test_configure_custom_copy
        self.assertEqual(style.configure(newname), default)
        ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    AssertionError: {'font': 'TkDefaultFont', 'foreground': 'sy[193 chars]: ''} != {'selectforeground': 'systemSelectedTextCol[193 chars]': 1}
      {'background': 'systemWindowBackgroundColor',
       'font': 'TkDefaultFont',
       'foreground': 'systemLabelColor',
       'insertwidth': 1,
       'selectbackground': 'systemSelectedTextBackgroundColor',
       'selectforeground': 'systemSelectedTextColor',
    -  'stipple': ''}
    ?             ^^
    
    +  'stipple': ()}
    ?             ^^
    
    
    ======================================================================
    FAIL: test_element_create_from_errors (test.test_ttk.test_style.StyleTest.test_element_create_from_errors)
    ----------------------------------------------------------------------
    _tkinter.TclError: theme "spam" does not exist
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/Users/barry/projects/python/3.13/Lib/test/test_ttk/test_style.py", line 225, in test_element_create_from_errors
        with self.assertRaisesRegex(TclError, 'theme "spam" doesn\'t exist'):
             ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    AssertionError: "theme "spam" doesn't exist" does not match "theme "spam" does not exist"
    
    ======================================================================
    FAIL: test_configure_image (test.test_ttk.test_widgets.ButtonTest.test_configure_image)
    ----------------------------------------------------------------------
    _tkinter.TclError: image "spam" does not exist
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/Users/barry/projects/python/3.13/Lib/test/test_tkinter/widget_tests.py", line 376, in test_configure_image
        self.checkImageParam(widget, 'image')
        ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
      File "/Users/barry/projects/python/3.13/Lib/test/test_ttk/test_widgets.py", line 185, in checkImageParam
        self.checkInvalidParam(widget, name, 'spam',
        ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
                errmsg='image "spam" doesn\'t exist')
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/barry/projects/python/3.13/Lib/test/test_tkinter/widget_tests.py", line 80, in checkInvalidParam
        with self.assertRaisesRegex(tkinter.TclError, errmsg or ''):
             ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    AssertionError: "\Aimage "spam" doesn't exist\Z" does not match "image "spam" does not exist"
    
    ======================================================================
    FAIL: test_configure_image (test.test_ttk.test_widgets.CheckbuttonTest.test_configure_image)
    ----------------------------------------------------------------------
    _tkinter.TclError: image "spam" does not exist
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/Users/barry/projects/python/3.13/Lib/test/test_tkinter/widget_tests.py", line 376, in test_configure_image
        self.checkImageParam(widget, 'image')
        ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
      File "/Users/barry/projects/python/3.13/Lib/test/test_ttk/test_widgets.py", line 185, in checkImageParam
        self.checkInvalidParam(widget, name, 'spam',
        ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
                errmsg='image "spam" doesn\'t exist')
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/barry/projects/python/3.13/Lib/test/test_tkinter/widget_tests.py", line 80, in checkInvalidParam
        with self.assertRaisesRegex(tkinter.TclError, errmsg or ''):
             ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    AssertionError: "\Aimage "spam" doesn't exist\Z" does not match "image "spam" does not exist"
    
    ======================================================================
    FAIL: test_virtual_event (test.test_ttk.test_widgets.ComboboxTest.test_virtual_event)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/Users/barry/projects/python/3.13/Lib/test/test_ttk/test_widgets.py", line 506, in test_virtual_event
        self.assertTrue(success)
        ~~~~~~~~~~~~~~~^^^^^^^^^
    AssertionError: [] is not true
    
    ======================================================================
    FAIL: test_configure_image (test.test_ttk.test_widgets.LabelTest.test_configure_image)
    ----------------------------------------------------------------------
    _tkinter.TclError: image "spam" does not exist
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/Users/barry/projects/python/3.13/Lib/test/test_tkinter/widget_tests.py", line 376, in test_configure_image
        self.checkImageParam(widget, 'image')
        ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
      File "/Users/barry/projects/python/3.13/Lib/test/test_ttk/test_widgets.py", line 185, in checkImageParam
        self.checkInvalidParam(widget, name, 'spam',
        ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
                errmsg='image "spam" doesn\'t exist')
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/barry/projects/python/3.13/Lib/test/test_tkinter/widget_tests.py", line 80, in checkInvalidParam
        with self.assertRaisesRegex(tkinter.TclError, errmsg or ''):
             ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    AssertionError: "\Aimage "spam" doesn't exist\Z" does not match "image "spam" does not exist"
    
    ======================================================================
    FAIL: test_configure_image (test.test_ttk.test_widgets.MenubuttonTest.test_configure_image)
    ----------------------------------------------------------------------
    _tkinter.TclError: image "spam" does not exist
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/Users/barry/projects/python/3.13/Lib/test/test_tkinter/widget_tests.py", line 376, in test_configure_image
        self.checkImageParam(widget, 'image')
        ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
      File "/Users/barry/projects/python/3.13/Lib/test/test_ttk/test_widgets.py", line 185, in checkImageParam
        self.checkInvalidParam(widget, name, 'spam',
        ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
                errmsg='image "spam" doesn\'t exist')
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/barry/projects/python/3.13/Lib/test/test_tkinter/widget_tests.py", line 80, in checkInvalidParam
        with self.assertRaisesRegex(tkinter.TclError, errmsg or ''):
             ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    AssertionError: "\Aimage "spam" doesn't exist\Z" does not match "image "spam" does not exist"
    
    ======================================================================
    FAIL: test_configure_image (test.test_ttk.test_widgets.RadiobuttonTest.test_configure_image)
    ----------------------------------------------------------------------
    _tkinter.TclError: image "spam" does not exist
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/Users/barry/projects/python/3.13/Lib/test/test_tkinter/widget_tests.py", line 376, in test_configure_image
        self.checkImageParam(widget, 'image')
        ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
      File "/Users/barry/projects/python/3.13/Lib/test/test_ttk/test_widgets.py", line 185, in checkImageParam
        self.checkInvalidParam(widget, name, 'spam',
        ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
                errmsg='image "spam" doesn\'t exist')
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/barry/projects/python/3.13/Lib/test/test_tkinter/widget_tests.py", line 80, in checkInvalidParam
        with self.assertRaisesRegex(tkinter.TclError, errmsg or ''):
             ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    AssertionError: "\Aimage "spam" doesn't exist\Z" does not match "image "spam" does not exist"
    
    ----------------------------------------------------------------------
    Ran 9 tests in 100.683s
    
    FAILED (failures=9)
    test test_ttk failed
    2 tests failed again:
        test_tkinter test_ttk

    I suspect it's because it's linking against Tcl/Tk 9.0.3 from homebrew and 3.13 isn't compatible with it. I'm not sure it's worth doing anything more in 3.13 given newer branches seem fine.

  13. 2 remaining items

  14. serhiy-storchaka commented on Jul 10, 2026

    @serhiy-storchaka
    Member

    #153484 does this.

  15. added a commit that references this issue on Jul 11, 2026
  16. smontanaro commented on Jul 11, 2026

    @smontanaro
    ContributorAuthor

    Very close. test_tkinter now passes. There's still a single test case failure in test_ttk:

    FAIL: test_configure_custom_copy (test.test_ttk.test_style.StyleTest.test_configure_custom_copy) (theme='aqua', name='.')
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/Users/skip/src/python/py3.13/Lib/test/test_ttk/test_style.py", line 164, in test_configure_custom_copy
        self.assertEqual(style.configure(newname), default)
        ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    AssertionError: {'font': 'TkDefaultFont', 'foreground': 'sy[193 chars]: ''} != {'selectforeground': 'systemSelectedTextCol[193 chars]': 1}
      {'background': 'systemWindowBackgroundColor',
       'font': 'TkDefaultFont',
       'foreground': 'systemLabelColor',
       'insertwidth': 1,
       'selectbackground': 'systemSelectedTextBackgroundColor',
       'selectforeground': 'systemSelectedTextColor',
    -  'stipple': ''}
    ?             ^^
    
    +  'stipple': ()}
    ?             ^^
  17. serhiy-storchaka commented on Jul 12, 2026

    @serhiy-storchaka
    Member

    Thanks for testing. This is Aqua-specific issue, not reproducible on Linux. Please check if #153611 fixes it.

  18. smontanaro commented on Jul 12, 2026

    @smontanaro
    ContributorAuthor

    Unfortunately, it doesn't. I get the same error after applying your patch:

    % ./python.exe -m test -v -ugui test_ttk
    == CPython 3.13.14+ experimental free-threading build (heads/3.13:caa4be2d497, Jul 11 2026, 16:55:57) [Clang 22.1.8 ]
    == macOS-26.5.2-arm64-arm-64bit-Mach-O little-endian
    == Python build: free_threading release
    == cwd: /Users/skip/src/python/py3.13/build/test_python_worker_2401æ
    == CPU count: 8
    == encodings: locale=UTF-8 FS=utf-8
    == resources (1): gui
    
    Using random seed: 2083467248
    0:00:00 load avg: 3.02 Run 1 test sequentially in a single process
    0:00:00 load avg: 3.02 [1/1] test_ttk
    ...
    ======================================================================
    FAIL: test_configure_custom_copy (test.test_ttk.test_style.StyleTest.test_configure_custom_copy) (theme='aqua', name='.')
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/Users/skip/src/python/py3.13/Lib/test/test_ttk/test_style.py", line 170, in test_configure_custom_copy
        self.assertEqual({k: norm(v) for k, v in copy.items()},
        ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                         default)
                         ^^^^^^^^
    AssertionError: {'font': 'TkDefaultFont', 'foreground': 'sy[193 chars]: ''} != {'selectforeground': 'systemSelectedTextCol[193 chars]': 1}
      {'background': 'systemWindowBackgroundColor',
       'font': 'TkDefaultFont',
       'foreground': 'systemLabelColor',
       'insertwidth': 1,
       'selectbackground': 'systemSelectedTextBackgroundColor',
       'selectforeground': 'systemSelectedTextColor',
    -  'stipple': ''}
    ?             ^^
    
    +  'stipple': ()}
    ?             ^^
    
    
    ----------------------------------------------------------------------
    Ran 397 tests in 18.306s
    
    FAILED (failures=1, skipped=15)
    test test_ttk failed
    0:00:18 load avg: 2.79 [1/1/1] test_ttk failed (1 failure)
    
    == Tests result: FAILURE ==
    
    1 test failed:
        test_ttk
    
    Total duration: 18.5 sec
    Total tests: run=397 failures=1 skipped=15
    Total test files: run=1/1 failed=1
    Result: FAILURE
    (py314) ~/src/python/py3.13% git diff
    diff --git a/Lib/test/test_ttk/test_style.py b/Lib/test/test_ttk/test_style.py
    index 56d8a5931fd..2e0a0384dd2 100644
    --- a/Lib/test/test_ttk/test_style.py
    +++ b/Lib/test/test_ttk/test_style.py
    @@ -161,9 +161,17 @@ def test_configure_custom_copy(self):
                         newname = f'C.{name}'
                         self.assertEqual(style.configure(newname), None)
                         style.configure(newname, **default)
    -                    self.assertEqual(style.configure(newname), default)
    +                    # With Tk 9 and the aqua theme an empty option value is
    +                    # read back as an empty tuple rather than an empty string
    +                    # (see gh-128846); normalize before comparing.
    +                    def norm(value):
    +                        return '' if value == () else value
    +                    copy = style.configure(newname)
    +                    self.assertEqual({k: norm(v) for k, v in copy.items()},
    +                                     default)
                         for key, value in default.items():
    -                        self.assertEqual(style.configure(newname, key), value)
    +                        self.assertEqual(norm(style.configure(newname, key)),
    +                                         value)
     
     
         def test_map_custom_copy(self):
    
  19. serhiy-storchaka commented on Jul 12, 2026

    @serhiy-storchaka
    Member

    What if replace return '' if value == () else value with return () if value == '' else value?

  20. smontanaro commented on Jul 12, 2026

    @smontanaro
    ContributorAuthor

    Yes, that works, thanks...

  21. added a commit that references this issue on Jul 14, 2026
  22. serhiy-storchaka commented on Jul 15, 2026

    @serhiy-storchaka
    Member

    Unfortunately that change breaks CI testing.

  23. added 2 commits that reference this issue on Jul 15, 2026
  24. serhiy-storchaka commented on Jul 20, 2026

    @serhiy-storchaka
    Member

    Please test with the current 3.13 branch.

  25. smontanaro commented on Jul 20, 2026

    @smontanaro
    ContributorAuthor

    Current 3.13 branch tests cleanly. Sorry for not trying sooner. I don't seem to get all pertinent notifications.

  26. serhiy-storchaka commented on Jul 20, 2026

    @serhiy-storchaka
    Member

    Thank you for verification. I am closing this issue as completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dirtopic-tkintertype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions