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.

classification
Title: Can not run test without test module for tests which import random module
Type: Stage: resolved
Components: Tests Versions: Python 3.8, Python 3.7, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: miss-islington, pablogsal, vajrasky, vstinner
Priority: normal Keywords: patch

Created on 2018-12-17 11:35 by vajrasky, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 11200 merged vstinner, 2018-12-17 15:44
PR 11202 merged miss-islington, 2018-12-17 21:06
Messages (7)
msg331992 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2018-12-17 11:35
$ 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.
msg331993 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-12-17 11:39
Your problem is that you have the Lib/test/bisect.py file. I renamed it to Lib/test/bisect_cmd.py.

Workarounds:

* Run the test using: ./python -m test test_xmlrpc
* Rename Lib/test/bisect.py to Lib/test/bisect_cmd.py

This bug is already fixed in the 2.7. You have to wait for the next 2.7 release to get the fix.
msg332002 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2018-12-17 13:13
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.
msg332012 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-12-17 15:40
> 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.
msg332022 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-12-17 21:06
New changeset 1dd035954bb03c41b954ebbd63969b4bcb0e106e by Victor Stinner in branch 'master':
bpo-35519: Rename test.bisect to test.bisect_cmd (GH-11200)
https://github.com/python/cpython/commit/1dd035954bb03c41b954ebbd63969b4bcb0e106e
msg332026 - (view) Author: miss-islington (miss-islington) Date: 2018-12-17 21:24
New changeset 05dfa0cc96f6b72b1e72f57b1b5f4b37764a382d by Miss Islington (bot) in branch '3.7':
bpo-35519: Rename test.bisect to test.bisect_cmd (GH-11200)
https://github.com/python/cpython/commit/05dfa0cc96f6b72b1e72f57b1b5f4b37764a382d
msg332027 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-12-17 21:38
I renamed Lib/test/bisect.py to Lib/test/bisect_cmd.py ;-)
History
Date User Action Args
2022-04-11 14:59:09adminsetgithub: 79700
2018-12-17 21:38:27vstinnersetstatus: open -> closed
versions: + Python 3.7, Python 3.8
messages: + msg332027

resolution: fixed
stage: patch review -> resolved
2018-12-17 21:24:56miss-islingtonsetnosy: + miss-islington
messages: + msg332026
2018-12-17 21:06:26miss-islingtonsetpull_requests: + pull_request10440
2018-12-17 21:06:13vstinnersetmessages: + msg332022
2018-12-17 15:44:12vstinnersetkeywords: + patch
stage: resolved -> patch review
pull_requests: + pull_request10439
2018-12-17 15:40:17vstinnersettitle: [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
2018-12-17 15:40:12vstinnersetstatus: closed -> open

nosy: + pablogsal
messages: + msg332012

resolution: fixed -> (no value)
2018-12-17 13:13:04vajraskysetmessages: + msg332002
2018-12-17 11:39:40vstinnersetstatus: open -> closed


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
nosy: + vstinner
versions: + Python 2.7, - Python 3.8
messages: + msg331993
resolution: fixed
stage: resolved
2018-12-17 11:35:16vajraskycreate