Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate gui available checks in test.support #62804

Closed
terryjreedy opened this issue Jul 31, 2013 · 13 comments
Closed

Consolidate gui available checks in test.support #62804

terryjreedy opened this issue Jul 31, 2013 · 13 comments
Assignees
Labels
tests Tests in the Lib/test dir topic-tkinter type-feature A feature request or enhancement

Comments

@terryjreedy
Copy link
Member

BPO 18604
Nosy @terryjreedy, @ned-deily, @ezio-melotti, @bitdancer, @zware
Files
  • issue18604.diff
  • issue18604.v2.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/ned-deily'
    closed_at = <Date 2014-11-02.02:48:34.428>
    created_at = <Date 2013-07-31.00:13:35.808>
    labels = ['tests', 'type-feature', 'expert-tkinter']
    title = 'Consolidate gui available checks in test.support'
    updated_at = <Date 2014-11-02.03:20:30.150>
    user = 'https://github.com/terryjreedy'

    bugs.python.org fields:

    activity = <Date 2014-11-02.03:20:30.150>
    actor = 'zach.ware'
    assignee = 'ned.deily'
    closed = True
    closed_date = <Date 2014-11-02.02:48:34.428>
    closer = 'ned.deily'
    components = ['Tests', 'Tkinter']
    creation = <Date 2013-07-31.00:13:35.808>
    creator = 'terry.reedy'
    dependencies = []
    files = ['33290', '35121']
    hgrepos = []
    issue_num = 18604
    keywords = ['patch']
    message_count = 13.0
    messages = ['193966', '193993', '207104', '217646', '217755', '217774', '217855', '217856', '217930', '219020', '219022', '230476', '230478']
    nosy_count = 6.0
    nosy_names = ['terry.reedy', 'ned.deily', 'ezio.melotti', 'r.david.murray', 'python-dev', 'zach.ware']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue18604'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5']

    @terryjreedy
    Copy link
    Member Author

    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.

    @terryjreedy terryjreedy added the type-feature A feature request or enhancement label Jul 31, 2013
    @bitdancer
    Copy link
    Member

    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.

    @zware
    Copy link
    Member

    zware commented Dec 30, 2013

    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

    @zware
    Copy link
    Member

    zware commented Apr 30, 2014

    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.

    @zware zware added tests Tests in the Lib/test dir topic-tkinter labels Apr 30, 2014
    @zware zware self-assigned this Apr 30, 2014
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented May 2, 2014

    New changeset 5f75eadecff1 by Zachary Ware in branch '2.7':
    Issue bpo-18604: Consolidated checks for GUI availability.
    http://hg.python.org/cpython/rev/5f75eadecff1

    New changeset eb361f69ddd1 by Zachary Ware in branch '3.4':
    Issue bpo-18604: Consolidated checks for GUI availability.
    http://hg.python.org/cpython/rev/eb361f69ddd1

    New changeset 82caec3865e3 by Zachary Ware in branch 'default':
    Closes bpo-18604: Merge with 3.4
    http://hg.python.org/cpython/rev/82caec3865e3

    @python-dev python-dev mannequin closed this as completed May 2, 2014
    @terryjreedy
    Copy link
    Member Author

    Thank you Zach.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented May 4, 2014

    New changeset 7ecb6e4b1077 by Ned Deily in branch '3.4':
    Issue bpo-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 bpo-18604: merge from 3.4
    http://hg.python.org/cpython/rev/7f6d9990a9b1

    @ned-deily
    Copy link
    Member

    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.

    @ned-deily ned-deily reopened this May 4, 2014
    @zware
    Copy link
    Member

    zware commented May 5, 2014

    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.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented May 24, 2014

    New changeset fef11a65a5e5 by Ned Deily in branch '2.7':
    Issue bpo-18604: Skip the Tk instantiation test on OS X because it can
    http://hg.python.org/cpython/rev/fef11a65a5e5

    @ned-deily
    Copy link
    Member

    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.

    @zware zware assigned ned-deily and unassigned zware Jul 1, 2014
    @ned-deily
    Copy link
    Member

    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 bpo-22770 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.

    @zware
    Copy link
    Member

    zware commented Nov 2, 2014

    Thanks for tracking it down, Ned!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    tests Tests in the Lib/test dir topic-tkinter type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants