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
test_code_module fails after test_idle #76017
Comments
$ ./python -m test -uall test_idle test_code_module
Run tests sequentially
0:00:00 load avg: 0.42 [1/2] test_idle
0:00:02 load avg: 0.42 [2/2] test_code_module
test test_code_module failed -- Traceback (most recent call last):
File "/home/serhiy/py/cpython/Lib/test/test_code_module.py", line 35, in test_ps1
self.assertEqual(self.sysmod.ps1, '>>> ')
AssertionError: <MagicMock name='sys.ps1' id='140109331413008'> != '>>> ' test_code_module failed 1 test failed: Total duration: 2 sec |
Running test_code_module afte test_idle, which somewhere executes idle code that sets sys.ps1, exposed a deficiency in test_code_module. TestInteractiveConsole.test_ps1 is intended to test this code in InteractiveConsole.interact. try:
sys.ps1
except AttributeError:
sys.ps1 = ">>> " The existing test only tried to test the except branch, but without insuring that the AttributeError occurs. PR 4070 fixes that and adds a test of the try branch, that sys.ps1 is respected and left alone (and later used as it) when present. Ditto for test_ps2. |
On the PR, Serhiy asks "Wouldn't be better to restore sys.ps1 in test_idle if it is changed here?" Aside from the fact that, as far as I know, it is not sanely possible to do so, I think it a bug for a test to be unnecessarily fragile. Both ps1 and ps2 are set when Python is in interactive mode. IDLE is only (partially) imitating Python's shell when it sets sys.ps1. The premise of python/cpython#69774 is that tests should accommodate sys.stdout and sys.stderr being None to the extent possible. I think the same applies to sys.ps1/2 being set. Indeed, as I reported on python/cpython#75942, in msg304298, 9 days ago, test_code_module tests test_ps1 and test_ps2 failed when I ran '>>> import test.autotest' in a *Python* shell. I did not understand the reason for the failures then, but if I had investigated, I should hope that I would have submitted the same PR, which fixes this autotest failure. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: