homepage

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.

classification
Title: Consolidate gui available checks in test.support
Type: enhancement Stage: resolved
Components: Tests, Tkinter Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ned.deily Nosy List: ezio.melotti, ned.deily, python-dev, r.david.murray, terry.reedy, zach.ware
Priority: normal Keywords: patch

Created on 2013年07月31日 00:13 by terry.reedy, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue18604.diff zach.ware, 2013年12月30日 20:20 review
issue18604.v2.diff zach.ware, 2014年04月30日 19:55 review
Messages (13)
msg193966 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013年07月31日 00:13
Current situation:
test.support.requires starts with
 if resource == 'gui' and not _is_gui_available():
On windows, _is_gui_available() uses ctypes to determine that there really is a graphics screen. On other systems, it just returns True, even when it should return False. The _is_gui_available check is repeated with each requires('gui') call even though all after the first would be redundant if False were somehow recorded. I think it should be. 
test/test_ttkguionly first tries to import _tkinter, as does test_idle, which initializes tcl/tk. It then calls tkinter.test.support.check_tk_availability. That either does a 'darwin'-ctypes check similar to the one for Windows in _is_gui_available (again to avoid a crash), or it tries to create a tk widget and looks for a TclError. Given that tcl has already been initialized successfully, the widget creation check is a gui-available check for non-Darwin systems. A global in tkinter.test.support records the result of the check so it is only run once.
If 'gui' is in use_resources, test_idle just does the widget check for *nix gui availability. It records a negative result by removing 'gui' from use_resources.
The tkinter system does not work for Idle because Idle tests use unittest test discovery instead of tkinter's custom test discovery. Given that, splitting test_idle into test_idle_text and test_idle_gui seems to not be possible. Anyway, if test_idle were to be split, categories like '_windows', '_dialogs', and '_extensions' would be much more sensible and useful.
----------------
For this issue, I propose:
1. Move the custom darwin gui check to test.support, after the custom windows gui check. It should be noted that a) Both of these are gui-framework independent; and b) Neither seems to be needed for any current buildbots (which makes it hard to verify that they work on current systems). However, they were needed in the past and might be again in the future, so each should be checked *once* in each regrtest run with 'gui' set.
2. If the crash-avoidance checks pass, run tkinter.Tk() as a final check on all systems (but especially those not covered by the first checks). But note in comments that this will have to change if tk is augmented or optionally replaced by another gui framework.
3. In requires(), run the above if 'gui' is set and requested, and record a negative result by unsetting 'gui' (removing it from use_resources). Perhaps output a note that this has been done. Subsequent gui requests will skip. I considered putting this logic in regrtest instead, but see 4.
4. Currently, requires never skips when the caller is the main module. Perhaps requires('gui') should skip even then when there is no gui system. This could happen if a no-gui system ran a console script with "python -m test.text_xxx".
5. Remove the current gui check from test_idle. Idle tests should continue to work as they are.
6. Revising test_tk and test_ttk_guionly to use the revised test.support would be a larger patch. It might best be done while modernizing the tkinter test system to use unittest discovery and .main, in another issue. I am still learning the details of the tkinter test system.
-----
To avoid immediate controversy, I marked this as an 'enhancement' for 3.4. But if the Mac 'darwin' check were currently needed, I would consider it a bug that it is buried in a tkinter function whose API is not right for Idle, instead of being in test.support. (And in 2.7, the function is buried in a module in a package with an illegal name.) So I think backporting should be considered.
msg193993 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013年07月31日 10:18
I think it is fine to backport this, since it only affects tests, and allows the backported idle tests to be consistent.
For 3/4, I agree that requires should skip always if the GUI infrastructure is not available. The "don't skip if main" logic is appropriate only for deciding whether or not to run the tests when the test suite is invoked directly (as opposed to through regrtest), not for deciding whether or not to run them when the actual resource is being checked.
msg207104 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2013年12月30日 20:20
Here's a patch for 3.4, and some sample verbose output[1] from the AMD64 Win7 buildbot (which runs buildbot as a service, and thus has no gui available).
[1] http://buildbot.python.org/all/builders/AMD64%20Windows7%20SP1%20custom/builds/40/steps/test/logs/stdio 
msg217646 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2014年04月30日 19:55
If there are no objections forthcoming, I'll try to get this applied to 3.4/3.5 later this week, then look into backporting to 2.7.
msg217755 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014年05月02日 15:52
New changeset 5f75eadecff1 by Zachary Ware in branch '2.7':
Issue #18604: Consolidated checks for GUI availability.
http://hg.python.org/cpython/rev/5f75eadecff1
New changeset eb361f69ddd1 by Zachary Ware in branch '3.4':
Issue #18604: Consolidated checks for GUI availability.
http://hg.python.org/cpython/rev/eb361f69ddd1
New changeset 82caec3865e3 by Zachary Ware in branch 'default':
Closes #18604: Merge with 3.4
http://hg.python.org/cpython/rev/82caec3865e3 
msg217774 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014年05月02日 18:41
Thank you Zach.
msg217855 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014年05月04日 02:25
New changeset 7ecb6e4b1077 by Ned Deily in branch '3.4':
Issue #18604: Skip the Tk instantiation test on OS X because it can
http://hg.python.org/cpython/rev/7ecb6e4b1077
New changeset 7f6d9990a9b1 by Ned Deily in branch 'default':
Issue #18604: merge from 3.4
http://hg.python.org/cpython/rev/7f6d9990a9b1 
msg217856 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2014年05月04日 02:35
For some reason, the newly-added Tk instantiation check causes the OS X Cocoa Tk to segfault when tests are run under regrtest -jn option, which causes each test to be run under a separate subprocess called from a separate thread. Somewhat surprisingly, the segfault doesn't seem to happen under the same conditions with 2.7, only with 3.4 and default, so there is something more at play here. But with the imminent tagging of 3.4.1rc1, I think it is better to disable the check for 3.4 (and default) on OS X pending further investigation. The check is redundant: if Tk doesn't work for some reason, the individual test should fail anyway, just a bit later.
msg217930 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2014年05月05日 16:07
Thanks Ned. Unfortunately, I don't have a Mac to test on, so I can't help much with figuring out what's going on.
msg219020 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014年05月24日 04:30
New changeset fef11a65a5e5 by Ned Deily in branch '2.7':
Issue #18604: Skip the Tk instantiation test on OS X because it can
http://hg.python.org/cpython/rev/fef11a65a5e5 
msg219022 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2014年05月24日 04:40
Earlier I noted: "Somewhat surprisingly, the segfault doesn't seem to happen under the same conditions with 2.7". I'm not sure now how I came to that conclusion then but it is incorrect: the segfault definitely also occurs under the same conditions with 2.7, at least when using the current ActiveTcl 8.5.15. It did not seem to fail with the Apple system Tk 8.5.9, a more plausible result than not failing at all with 2.7. Next step: test with various Cocoa Tk versions.
msg230476 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2014年11月02日 02:48
The previous segfaults on OS X have been isolated to a problem in Cocoa Tk and an issue has been opened about it on the Tk issue tracker. See Issue22770 for details. Changesets applied to _is_gui_available() in that issue should prevent the segfaults by ensuring that Tk completes necessary initialization before the Tcl interpreter instance is destroyed and a new one created. So _is_gui_available() is now enabled on OS X and we can close this issue.
msg230478 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2014年11月02日 03:20
Thanks for tracking it down, Ned!
History
Date User Action Args
2022年04月11日 14:57:48adminsetgithub: 62804
2014年11月02日 03:20:30zach.waresetmessages: + msg230478
2014年11月02日 02:48:34ned.deilysetstatus: open -> closed
resolution: fixed
messages: + msg230476

stage: resolved
2014年07月01日 19:43:36zach.waresetassignee: zach.ware -> ned.deily
resolution: fixed -> (no value)
2014年05月24日 04:40:20ned.deilysetmessages: + msg219022
stage: resolved -> (no value)
2014年05月24日 04:30:26python-devsetmessages: + msg219020
2014年05月05日 16:07:30zach.waresetmessages: + msg217930
2014年05月04日 02:35:35ned.deilysetstatus: closed -> open
versions: + Python 2.7
nosy: + ned.deily

messages: + msg217856
2014年05月04日 02:25:58python-devsetmessages: + msg217855
2014年05月02日 18:41:31terry.reedysetmessages: + msg217774
2014年05月02日 15:52:44python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg217755

resolution: fixed
stage: patch review -> resolved
2014年04月30日 19:55:59zach.waresetfiles: + issue18604.v2.diff
versions: + Python 3.5
messages: + msg217646

assignee: zach.ware
components: + Tests, Tkinter
2014年01月02日 15:12:13zach.waresetstage: needs patch -> patch review
2013年12月30日 20:20:18zach.waresetfiles: + issue18604.diff

nosy: + zach.ware
messages: + msg207104

keywords: + patch
2013年08月08日 14:00:25ezio.melottisetnosy: + ezio.melotti
2013年07月31日 10:18:27r.david.murraysetnosy: + r.david.murray
messages: + msg193993
2013年07月31日 00:13:35terry.reedycreate

AltStyle によって変換されたページ (->オリジナル) /