-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Comments
$ 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: 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. |
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. |
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. |
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. |
I renamed Lib/test/bisect.py to Lib/test/bisect_cmd.py ;-) |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: