Skip to content
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

Closed
serhiy-storchaka opened this issue Oct 21, 2017 · 5 comments
Closed

test_code_module fails after test_idle #76017

serhiy-storchaka opened this issue Oct 21, 2017 · 5 comments
Assignees
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

BPO 31836
Nosy @terryjreedy, @serhiy-storchaka
PRs
  • bpo-31836: Test_code_module now passes with sys.ps1, ps2 set #4070
  • [3.6] bpo-31836: Test_code_module now passes with sys.ps1, ps2 set (GH-4070) #4156
  • 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:

    assignee = 'https://github.com/terryjreedy'
    closed_at = <Date 2017-10-28.11:44:06.434>
    created_at = <Date 2017-10-21.16:03:19.215>
    labels = ['3.7', 'tests', 'type-bug', 'library']
    title = 'test_code_module fails after test_idle'
    updated_at = <Date 2017-10-28.11:44:06.433>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2017-10-28.11:44:06.433>
    actor = 'terry.reedy'
    assignee = 'terry.reedy'
    closed = True
    closed_date = <Date 2017-10-28.11:44:06.434>
    closer = 'terry.reedy'
    components = ['Library (Lib)', 'Tests']
    creation = <Date 2017-10-21.16:03:19.215>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31836
    keywords = ['patch']
    message_count = 5.0
    messages = ['304709', '304720', '304758', '305146', '305157']
    nosy_count = 2.0
    nosy_names = ['terry.reedy', 'serhiy.storchaka']
    pr_nums = ['4070', '4156']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue31836'
    versions = ['Python 3.6', 'Python 3.7']

    @serhiy-storchaka
    Copy link
    Member Author

    $ ./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 OK.

    1 test failed:
    test_code_module

    Total duration: 2 sec
    Tests result: FAILURE

    @serhiy-storchaka serhiy-storchaka added tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error labels Oct 21, 2017
    @terryjreedy
    Copy link
    Member

    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.

    @terryjreedy terryjreedy added stdlib Python modules in the Lib dir and removed topic-IDLE labels Oct 21, 2017
    @terryjreedy
    Copy link
    Member

    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.

    @terryjreedy
    Copy link
    Member

    New changeset 5a4bbcd by Terry Jan Reedy in branch 'master':
    bpo-31836: Test_code_module now passes with sys.ps1, ps2 set (bpo-4070)
    5a4bbcd

    @terryjreedy
    Copy link
    Member

    New changeset 8ed5644 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) (bpo-4156)
    8ed5644

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life stdlib Python modules in the Lib dir tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants