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.

Title: test_code_module fails after test_idle
Type: behavior Stage: resolved
Components: Library (Lib), Tests Versions: Python 3.7, Python 3.6
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: serhiy.storchaka, terry.reedy
Priority: normal Keywords: patch

Created on 2017-10-21 16:03 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 4070 merged terry.reedy, 2017-10-21 19:46
PR 4156 merged python-dev, 2017-10-28 01:45
Messages (5)
msg304709 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-10-21 16:03
$ ./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/", line 35, in test_ps1
    self.assertEqual(self.sysmod.ps1, '>>> ')
AssertionError: <MagicMock name='sys.ps1' id='140109331413008'> != '>>> '

test_code_module failed
1 test OK.

1 test failed:

Total duration: 2 sec
Tests result: FAILURE
msg304720 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-10-21 20:06
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.

        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.
msg304758 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-10-22 18:25
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 #25588 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 #31761, 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.
msg305146 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-10-28 01:45
New changeset 5a4bbcd479ce86f68bbe12bc8c16e3447f32e13a by Terry Jan Reedy in branch 'master':
bpo-31836: Test_code_module now passes with sys.ps1, ps2 set (#4070)
msg305157 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-10-28 11:43
New changeset 8ed5644f78e57cd59813097b35906ad6f1775f95 by Terry Jan Reedy (Miss Islington (bot)) in branch '3.6':
bpo-31836: Test_code_module now passes with sys.ps1, ps2 set (GH-4070) (#4156)
Date User Action Args
2022-04-11 14:58:53adminsetgithub: 76017
2017-10-28 11:44:06terry.reedysetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-10-28 11:43:20terry.reedysetmessages: + msg305157
2017-10-28 01:45:28python-devsetstage: patch review
pull_requests: + pull_request4126
2017-10-28 01:45:21terry.reedysetmessages: + msg305146
2017-10-22 18:26:00terry.reedysetmessages: + msg304758
2017-10-21 20:06:52terry.reedysetmessages: + msg304720
components: + Library (Lib), - IDLE
stage: patch review -> (no value)
2017-10-21 19:46:20terry.reedysetkeywords: + patch
stage: patch review
pull_requests: + pull_request4041
2017-10-21 16:03:19serhiy.storchakacreate