Skip to content

test_code_module fails after test_idle #76017

Closed

Description

@serhiy-storchaka
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']

    Activity

    1. serhiy-storchaka commented on Oct 21, 2017

      @serhiy-storchaka
      MemberAuthor
      $ ./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

    2. added
      tests
      type-bug
      on Oct 21, 2017
    3. terryjreedy commented on Oct 21, 2017

      @terryjreedy
      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.

    4. added
      stdlib
      and removed on Oct 21, 2017
    5. terryjreedy commented on Oct 22, 2017

      @terryjreedy
      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.
    6. terryjreedy commented on Oct 28, 2017

      @terryjreedy
      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

    7. terryjreedy commented on Oct 28, 2017

      @terryjreedy
      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

    8. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    3.7 (EOL)stdlibteststype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions