This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: test_tix cannot import _default_root after test_idle
Type: behavior Stage: resolved
Components: Tests Versions: Python 3.6, Python 3.5, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: martin.panter, python-dev, serhiy.storchaka, terry.reedy, zach.ware
Priority: normal Keywords: patch

Created on 2016-07-25 02:07 by martin.panter, last changed 2022-04-11 14:58 by admin. This issue is now closed.

File name Uploaded Description Edit
tix_default_root.patch serhiy.storchaka, 2016-07-25 03:02 review
Pull Requests
URL Status Linked Edit
PR 552 closed dstufft, 2017-03-31 16:36
Messages (14)
msg271206 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-07-25 02:07
$ ./python -m unittest -v test.test_{idle,tix}
. . .
test_tix (unittest.loader._FailedTest) ... ERROR

ERROR: test_tix (unittest.loader._FailedTest)
ImportError: Failed to import test module: test_tix
Traceback (most recent call last):
  File "/media/disk/home/proj/python/cpython/Lib/unittest/", line 153, in loadTestsFromName
    module = __import__(module_name)
  File "/media/disk/home/proj/python/cpython/Lib/test/", line 11, in <module>
    from tkinter import tix, TclError
  File "/media/disk/home/proj/python/cpython/Lib/tkinter/", line 30, in <module>
    from tkinter import _cnfmerge, _default_root
ImportError: cannot import name '_default_root'

Without test_idle, test_tix is skipped for me:

$ ./python -m unittest -v test.test_tix
test_tix_available (test.test_tix.TestTix) ... skipped 'Tix not available'

Reverting to before revision 064b29dde096 (Issue 24137) also fixes the failure.
msg271219 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-07-25 03:02
There is a bug in tix. _default_root shouldn't be imported, since this is modifiable attribute.
msg271220 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-07-25 03:10
I could reverse the effect of test_idle calling tk.NoDefaultRoot by adding
    tk._support_default_root = 1
    tk._default_root = None
at the very end, but I take Serhiy's comment as suggesting that there should be no need.
msg271221 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2016-07-25 03:34
I think there are two bugs to be fixed here:

1) as Serhiy said, if tix needs _default_root, it should use it as tkinter._default_root instead of importing it directly

2) test_idle should not permanently modify the tkinter namespace
msg271225 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-07-25 04:32
New changeset 5c76f787e695 by Terry Jan Reedy in branch 'default':
Issue #24137, issue #27611: Restore tkinter after test_idle.
msg271226 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-07-25 04:37
#24137 only patched default, so either too many versions were selected or there is another bug in test_tix. Martin and Serhiy can sort that out.

The restore patch I pushed is based on this from tkinter.__init__
_support_default_root = 1
_default_root = None

def NoDefaultRoot():
    """Inhibit setting of default root window.

    Call this function to inhibit that the first instance of
    Tk is used for windows without an explicit parent window.
    global _support_default_root
    _support_default_root = 0
    global _default_root
    _default_root = None
    del _default_root
msg272822 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-08-16 04:10
New changeset a6a248479b66 by Terry Jan Reedy in branch 'default':
Issue #27611, #24137: Only change tkinter when easily restored.
msg272823 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-08-16 04:11
Ned Deily noticed the same problem when running with test.regrtest #27714.

I cannot reproduce this issue when running both tests either with unittest or test.regrtest.

F:\Python\dev>36\pcbuild\win32\python_d.exe -m unittest test.test_tix test.test_idle test.test_tix
Ran 221 tests in 3.959s

F:\Python\dev>36\pcbuild\win32\python_d.exe -m test -ugui test_tix test_idle test_tix
Run tests sequentially
0:00:00 [1/3] test_tix
0:00:00 [2/3] test_idle
0:00:03 [3/3] test_tix
All 3 tests OK.
 if __name__ == '__main__':
     unittest.main(verbosity=2, exit=False)
+    tk._support_default_root = 1
+    tk._default_root = None

Zach, I don't know of any way to get either unittest or test.regrtest to run anything in test_idle after it runs the test collector *and* the tests.  Do you?

The addition of tk.NoDefaultRoot() to both IDLE and its tests was suggested by Serhiy in #24137.  Doing so exposed several issues in htests but no real bugs in IDLE itself. My patch to restore tkinter module only works when test_idle is run as main.  So as far as that patch goes, tkinter should only changed when the test is run as main.  I will move the call.  I have already changed my check script to run test_idle this way.

Otherwise, the easiest way to leave tkinter as it was when testing ends is to not change it.  I am aware that tkinter tests avoid the  by defining a mixin class with class methods that call and undo the call.  It is used in 11 test classes within the tkinter and ttk tests.  However, this refactoring would be harder to apply to IDLE tests and not sufficient in itself.  It is at best a future project.

I added a guard to IDLE's NoDefaultRoot call for when pyshell.main is broken into multiple testable functions.
msg272839 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-08-16 05:44
New changeset cddd633b959f by Terry Jan Reedy in branch '2.7':
Issue #27611: Don't import volatile attribute.

New changeset a42933335897 by Terry Jan Reedy in branch '3.5':
Issue #27611: Don't import volatile attribute.
msg272844 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-08-16 07:09
Terry, you committed not full patch. The tix module still doesn't work after NoDefaultRoot().
msg272846 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-08-16 07:19
What do you mean by 'does not work' and what did I omit?
msg272860 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-08-16 14:25
DisplayStyle() fails with AttributeError after NoDefaultRoot(). Should be made following changes:

1. The refwindow option should have priority over _default_root.
2. Add the master keyword-only parameter for creating styles without refwindow (3.6 only).
msg272862 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-08-16 15:55
This issue is about test_tix failing when run after test_idle, due to the conjunction of two specific causes, one old (tix importing _default_root), one new (IDLE deleting and not restoring _default_root).  The new cause exposed the old.  Fixing either cause would have negated the conjunction, but at Zack's urging, I fixed both.  I even did one extra bit of cleanup in moving the tkinter and os imports to the top where they belong.  In my view, my patch was more than complete and this issue is fixed and should have remained closed and should be reclosed.

Serhiy, when I wrote the tix patch, I was aware that tix remains buggy in that it will fail if a *user* imports tix, removes _default_root, and calls either of the functions that unconditionally access the attribute.  Since test_tix only tests that the tix can be imported and that tix.Tk runs, there may be more bugs.  And more cleanups might be needed.  However, patching tix to work better is a different issue than this one.  If you want, open a new issue, add some tests, and write the patch you outlined.
msg277376 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-09-25 13:54
New changeset 94a26aa1b1e0 by Serhiy Storchaka in branch '2.7':
Issue #27611: Fixed support of default root window in the Tix module.

New changeset 7b458bcdab75 by Serhiy Storchaka in branch '3.5':
Issue #27611: Fixed support of default root window in the tkinter.tix module.

New changeset ec3f5d21bec0 by Serhiy Storchaka in branch '3.6':
Issue #27611: Fixed support of default root window in the tkinter.tix module.

New changeset 1c5e0dbcb2a0 by Serhiy Storchaka in branch 'default':
Issue #27611: Fixed support of default root window in the tkinter.tix module.
Date User Action Args
2022-04-11 14:58:34adminsetgithub: 71798
2017-03-31 16:36:37dstufftsetpull_requests: + pull_request1089
2016-09-25 14:45:24serhiy.storchakasetstatus: open -> closed
2016-09-25 13:54:44python-devsetmessages: + msg277376
2016-08-16 15:55:47terry.reedysetassignee: terry.reedy ->
messages: + msg272862
2016-08-16 14:25:35serhiy.storchakasetmessages: + msg272860
2016-08-16 07:19:24terry.reedysetmessages: + msg272846
2016-08-16 07:09:46serhiy.storchakasetstatus: closed -> open

messages: + msg272844
2016-08-16 05:46:09terry.reedysetstatus: open -> closed
assignee: terry.reedy
resolution: fixed
stage: patch review -> resolved
2016-08-16 05:44:52python-devsetmessages: + msg272839
2016-08-16 04:11:24terry.reedysetmessages: + msg272823
2016-08-16 04:10:31python-devsetmessages: + msg272822
2016-07-25 04:37:35terry.reedysetmessages: + msg271226
2016-07-25 04:32:09python-devsetnosy: + python-dev
messages: + msg271225
2016-07-25 03:34:54zach.waresetnosy: + zach.ware
messages: + msg271221
2016-07-25 03:10:06terry.reedysetmessages: + msg271220
2016-07-25 03:02:43serhiy.storchakasetfiles: + tix_default_root.patch
versions: + Python 2.7, Python 3.5
messages: + msg271219

keywords: + patch
stage: patch review
2016-07-25 02:07:16martin.pantercreate