IDLE: protect macOS Tk() call when no GUI
The no-gui (mock Text) test_squeezer.SqueezerTest.test_write_stdout indirectly calls squeezer.Squeezer.mywrite, which calls macosx.isAquaTk, which calls _init_tk_type, which calls tkinter.Tk to initialize macosx._tk_type. When a test is run on macOS with no GUI, this crashes; see #97032 for an example.
test_squeezer later calls isAquaTk directly. Even if we fix test_squeezer, there are about 10 other isAquaTk calls in idlelib that someday might be triggered by more complete tests. I will try patching _init_tk_type in branch tktype to skip Tk() when it would crash.
The fix in #97530 for a testing-only bug, merged after 3.11.rc2, introduced a runtime-only bug of disable IDLE startup when test/* is not installed. This bug was released in 3.12.0a1, 3.10.8, and Microsoft Python 3.10.2288.0. It was reported on SO for the last: https://stackoverflow.com/questions/74070702/python-m-idlelib-idle-not-working-windows-10/74082858#74082858.
The immediate fix for anyone is to delete the import on line 7 and replace the try suite on line 23 with pass. Windows people who omitted the test suite can Modify and add it.
@pablogsal I hope you did not cherr-pick the buggy 'fix' into 3.11.0. If you did, I will have a better fix soon.
@zooba Does MS Python allow installing the test? Once the new fix is merged, could you let the MS Python person know?
@ned-deily As near as I could tell, one cannot install psf mac python without the tests. Correct? Do you know about homebrew? (And will we ever be rid of some of the mac graphics options?)
[Longer term, I want to consolidate macosx imports and if possible only do them on mac.]
All cherry picks will be done hours before the release so we are safe. Just tell me what you want me to add and I will make sure is there the day of the final release .
#98313 follows on #97530. Reversion or #97530 or merging of #98313 would only be essential if #97530 had already been merged. The net effect of both is to prevent test_idle possibly crashing macOS with no GUI, now or with test revisions. AFAIK, CI and buildbots only run current repository versions, not release versions. So I don't think the release needs any change.
@terryjreedy No, the Store package doesn't have any way to install the test suite. If we need those helpers, they should be copied elsewhere (either idlelib, tkinter or unittest probably - I'll let you make that call).
That said, if they're only needed for Mac, then handling the import error should also be fine.