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

Can not run test without test module for tests which import random module #79700

Closed
vajrasky mannequin opened this issue Dec 17, 2018 · 7 comments
Closed

Can not run test without test module for tests which import random module #79700

vajrasky mannequin opened this issue Dec 17, 2018 · 7 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes tests Tests in the Lib/test dir

Comments

@vajrasky
Copy link
Mannequin

vajrasky mannequin commented Dec 17, 2018

BPO 35519
Nosy @vstinner, @vajrasky, @pablogsal, @miss-islington
PRs
  • bpo-35519: Rename test.bisect to test.bisect_cmd #11200
  • [3.7] bpo-35519: Rename test.bisect to test.bisect_cmd (GH-11200) #11202
  • 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 = None
    closed_at = <Date 2018-12-17.21:38:27.639>
    created_at = <Date 2018-12-17.11:35:16.261>
    labels = ['3.8', '3.7', 'tests']
    title = 'Can not run test without test module for tests which import random module'
    updated_at = <Date 2018-12-17.21:38:27.606>
    user = 'https://github.com/vajrasky'

    bugs.python.org fields:

    activity = <Date 2018-12-17.21:38:27.606>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-12-17.21:38:27.639>
    closer = 'vstinner'
    components = ['Tests']
    creation = <Date 2018-12-17.11:35:16.261>
    creator = 'vajrasky'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 35519
    keywords = ['patch']
    message_count = 7.0
    messages = ['331992', '331993', '332002', '332012', '332022', '332026', '332027']
    nosy_count = 4.0
    nosy_names = ['vstinner', 'vajrasky', 'pablogsal', 'miss-islington']
    pr_nums = ['11200', '11202']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue35519'
    versions = ['Python 2.7', 'Python 3.7', 'Python 3.8']

    @vajrasky
    Copy link
    Mannequin Author

    vajrasky mannequin commented Dec 17, 2018

    $ git clone git@github.com:python/cpython.git cpython2
    $ cd cpython2
    $ ./configure --with-pydebug
    $ make -j
    $ ./python Lib/test/test_xmlrpc.py 
    Traceback (most recent call last):
      File "Lib/test/test_xmlrpc.py", line 8, in <module>
        import xmlrpc.client as xmlrpclib
      File "/opt/Code/python/cpython2/Lib/xmlrpc/client.py", line 136, in <module>
        import http.client
      File "/opt/Code/python/cpython2/Lib/http/client.py", line 71, in <module>
        import email.parser
      File "/opt/Code/python/cpython2/Lib/email/parser.py", line 12, in <module>
        from email.feedparser import FeedParser, BytesFeedParser
      File "/opt/Code/python/cpython2/Lib/email/feedparser.py", line 27, in <module>
        from email._policybase import compat32
      File "/opt/Code/python/cpython2/Lib/email/_policybase.py", line 9, in <module>
        from email.utils import _has_surrogates
      File "/opt/Code/python/cpython2/Lib/email/utils.py", line 28, in <module>
        import random
      File "/opt/Code/python/cpython2/Lib/random.py", line 47, in <module>
        import bisect as _bisect
      File "/opt/Code/python/cpython2/Lib/test/bisect.py", line 27, in <module>
        import tempfile
      File "/opt/Code/python/cpython2/Lib/tempfile.py", line 45, in <module>
        from random import Random as _Random
    ImportError: cannot import name 'Random' from 'random' (/opt/Code/python/cpython2/Lib/random.py)

    I know about running test this way:
    $ ./python -m test -v test_xmlrpc

    And it works.

    I am just wondering whether I should be able to run test this way: ./python Lib/test/test_blabla.py?

    Because running other tests without test module works, for example: ./python Lib/test/test_ast.py. Only test which imports random module fails.

    @vajrasky vajrasky mannequin added 3.8 only security fixes tests Tests in the Lib/test dir labels Dec 17, 2018
    @vstinner
    Copy link
    Member

    Your problem is that you have the Lib/test/bisect.py file. I renamed it to Lib/test/bisect_cmd.py.

    Workarounds:

    This bug is already fixed in the 2.7. You have to wait for the next 2.7 release to get the fix.

    @vstinner vstinner removed the 3.8 only security fixes label Dec 17, 2018
    @vstinner vstinner changed the title Can not run test without test module for tests which import random module [2.7] Can not run test without test module for tests which import random module Dec 17, 2018
    @vajrasky
    Copy link
    Mannequin Author

    vajrasky mannequin commented Dec 17, 2018

    Okay, thanks, Victor. Your suggestion to rename Lib/test/bisect.py to Lib/test/bisect_cmd.py works. My question is why you fixed in 2.7 branch only? This problem persists in master (3.8).

    Ah, I think because I use cpython2 directory name, you thought I used Python 2. cpython2 is just a directory name. It has nothing to do with Python 2. I used master when finding this bug.

    @vstinner
    Copy link
    Member

    Ah, I think because I use cpython2 directory name, you thought I used Python 2. cpython2 is just a directory name. It has nothing to do with Python 2. I used master when finding this bug.

    Ah right, I can reproduce the issue in master:

    vstinner@apu$ ./python Lib/test/test_xmlrpc.py 
    Traceback (most recent call last):
      File "Lib/test/test_xmlrpc.py", line 8, in <module>
        import xmlrpc.client as xmlrpclib
      File "/home/vstinner/prog/python/master/Lib/xmlrpc/client.py", line 136, in <module>
        import http.client
      File "/home/vstinner/prog/python/master/Lib/http/client.py", line 71, in <module>
        import email.parser
      File "/home/vstinner/prog/python/master/Lib/email/parser.py", line 12, in <module>
        from email.feedparser import FeedParser, BytesFeedParser
      File "/home/vstinner/prog/python/master/Lib/email/feedparser.py", line 27, in <module>
        from email._policybase import compat32
      File "/home/vstinner/prog/python/master/Lib/email/_policybase.py", line 9, in <module>
        from email.utils import _has_surrogates
      File "/home/vstinner/prog/python/master/Lib/email/utils.py", line 28, in <module>
        import random
      File "/home/vstinner/prog/python/master/Lib/random.py", line 47, in <module>
        import bisect as _bisect
      File "/home/vstinner/prog/python/master/Lib/test/bisect.py", line 27, in <module>
        import tempfile
      File "/home/vstinner/prog/python/master/Lib/tempfile.py", line 45, in <module>
        from random import Random as _Random
    ImportError: cannot import name 'Random' from 'random' (/home/vstinner/prog/python/master/Lib/random.py)

    Hum. We should either rename Lib/test/bisect.py to Lib/test/bisect_cmd.py or move the feature into libregrtest.

    @vstinner vstinner reopened this Dec 17, 2018
    @vstinner vstinner changed the title [2.7] Can not run test without test module for tests which import random module Can not run test without test module for tests which import random module Dec 17, 2018
    @vstinner
    Copy link
    Member

    New changeset 1dd0359 by Victor Stinner in branch 'master':
    bpo-35519: Rename test.bisect to test.bisect_cmd (GH-11200)
    1dd0359

    @miss-islington
    Copy link
    Contributor

    New changeset 05dfa0c by Miss Islington (bot) in branch '3.7':
    bpo-35519: Rename test.bisect to test.bisect_cmd (GH-11200)
    05dfa0c

    @vstinner
    Copy link
    Member

    I renamed Lib/test/bisect.py to Lib/test/bisect_cmd.py ;-)

    @vstinner vstinner added 3.7 (EOL) end of life 3.8 only security fixes labels Dec 17, 2018
    @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 3.8 only security fixes tests Tests in the Lib/test dir
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants