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: turtledemo modules imported by test___all__ cause side effects or failures
Type: Stage: resolved
Components: Tests Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: jesstess, ned.deily, pitrou, python-dev, terry.reedy
Priority: normal Keywords: easy

Created on 2014-06-29 23:56 by ned.deily, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (8)
msg221921 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2014-06-29 23:56
Although the turtledemo modules are not run directly during by "make test" or by "python -m test -uall", they are currently being inadvertently imported by test___all__.  This can lead to test failures and side effects because some of the turtledemo modules execute code on import, rather than only when being run via calls to their main() functions.  A quick glance shows problems with the following demos: clock (calls mode("logo") which causes a window to appear), colormixer (which unconditionally calls sys.setrecursionlimit()), and two_canvases (which is not structured using functions at all).  Depending on how tests are run, these problems can cause serious side effects.

At a minimum,
1. test___all__ should be changed to exclude turtledemo modules.

It would also be nice to make the demos better citizens:
2. move the mode() call to main() in clock
3. move the setrecursionlimit call to main() and save and restore the original value on exit
4. restructure two_canvases to be like the other demos.
5. double-check all demos for other cases where interpreter state is changed and not restored.
msg221922 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-06-30 00:11
> 1. test___all__ should be changed to exclude turtledemo modules.

Agreed. In general, the test suite shouldn't open any GUI windows except if the "gui" resource is enabled (which isn't the default).
The turtledemo behaviour is quite new in that regard.
msg221937 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-06-30 02:12
6. Add 'good citizenship' note to demohelp.txt. Also point out that all turtle initialiazation should be in main anyway (see 2. and 3. below). Demo should run independently of what other demos do.

re 2: If the mode call is needed, it is a bug that it is not main() as another demo could change it.

re 3: ditto, though much less likely.

re 4: As mentioned in #14117, two_canvases is buggy in that the code is not displayed. I added a comment in the file about things that don't work. A main function is the next thing to try anyway.

If no one does the turtledemo changes, I probably will soon.
msg221966 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-06-30 16:17
I am working on the turtle demos now. Victor gave more info in #21884.

I was partly wrong in my comments. turtledemo uses reload to re-initialize demos when one switches between them. I am tempted to remove this as part of discouraging side-effects on import. It is not a good example to be followed.
msg221978 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-06-30 20:10
New changeset c173a34f20c0 by Terry Jan Reedy in branch '2.7':
Issue #21882: In turtle demos, remove module scope gui and sys calls by
http://hg.python.org/cpython/rev/c173a34f20c0

New changeset fcfa9c5a00fd by Terry Jan Reedy in branch '3.4':
Issue #21882: In turtle demos, remove module scope gui and sys calls by
http://hg.python.org/cpython/rev/fcfa9c5a00fd
msg221981 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-06-30 20:28
2. Done
3. I just removed the setrecursionlimit call, added for 3.0. I moved the colormixer sliders around for longer than anyone is likely to and it ran fine.
4. two-canvases works fine now. The extra window just has to be clicked away.
5. nim had a call to turtle.Screen, now in main().
6. Done
Let's see what the buildbots say.

1. Since demos are part of the delivered stdlib, it could be argued that they should get minimal sanity check of being importable. I don't care either way. I leave this to either of you.
msg221988 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-06-30 22:11
The __all__ test now passes on Snow Leapard.
msg223772 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-07-23 20:00
I opened #22051 about removing reload to force better code. Since the tests are passing and I think the demo modules should be minimally tested by importing, and no one has said otherwise since the fix, I am closing this.
History
Date User Action Args
2022-04-11 14:58:05adminsetgithub: 66081
2014-07-23 20:00:27terry.reedysetstatus: open -> closed
resolution: fixed
messages: + msg223772

stage: commit review -> resolved
2014-06-30 22:11:35terry.reedysetmessages: + msg221988
2014-06-30 20:28:30terry.reedysetassignee: terry.reedy ->
messages: + msg221981
stage: test needed -> commit review
2014-06-30 20:10:14python-devsetnosy: + python-dev
messages: + msg221978
2014-06-30 19:11:14ned.deilylinkissue21884 superseder
2014-06-30 16:30:14terry.reedylinkissue14117 dependencies
2014-06-30 16:17:13terry.reedysetassignee: terry.reedy
messages: + msg221966
2014-06-30 13:28:56r.david.murraysetnosy: + jesstess
2014-06-30 02:13:00terry.reedysetmessages: + msg221937
versions: + Python 2.7
2014-06-30 00:11:57pitrousetnosy: + terry.reedy, pitrou
messages: + msg221922
2014-06-29 23:56:01ned.deilycreate