bpo-31836: Test_code_module now passes with sys.ps1, ps2 set#4070
bpo-31836: Test_code_module now passes with sys.ps1, ps2 set#4070terryjreedy merged 4 commits intopython:masterfrom
Conversation
Test_code_module assume sys.ps1 is initially absent; make it so. Add test that code.interact respects existing sys.ps1. Ditto for ps2.
|
Wouldn't be better to restore |
|
A program that needs sys.ps1/2 in particular states should set the state it needs. Test_code_module needs them both unset and set to a non-default string. Running test_code_module after test_idle exposed the same bug that was exposed previously by running autotest in a Python shell. The current patch prevents the autotest test_code_module failure that I saw previously. See the issue for more. |
|
The full test suite passes on my Win10 machine. |
|
I think this issue should be fixed on both sides. Tests that change module globals should restore them after testing. And |
|
Tests routine mutate sys.modules and add attributes to other modules without 'restoring' them. For instance, test_tk adds at least .font, .test, and .ttk to tkinter. sys.ps1 is at least as expected as these. However, on reading the IDLE code, I decided it would be improved by adding a PyShell() attribute set from sys.ps1 when it exists, and never modifying sys. (The code module could do the same.) I made this a separate issue (bpo-31858) and PR (#4143). I plan to push both tomorrow. |
|
I suggest to not change Actually |
|
After the update merge, which included the change to IDLE not setting sys.ps1, test_code_module continues to pass the real test, which is running with |
|
Thanks @terryjreedy for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6. |
|
GH-4156 is a backport of this pull request to the 3.6 branch. |
The code module uses sys.ps1 if present or sets it to '>>> ' if not.
Test_code_module now properly tests both behaviors. Ditto for ps2.
https://bugs.python.org/issue31836