测试人社区

【基础问题】在pycharm执行selenium打开浏览器程序抛make sure your test modules/packages have valid Python names.

在pycharm执行selenium打开浏览器程序抛make sure your test modules/packages have valid Python names,在终端上执行正常,麻烦老师帮忙看下,是哪里配置不对?

/Users/yukuai/Yu12ProTesting/bin/python /Applications/PyCharm.app/Contents/helpers/pycharm/_jb_pytest_runner.py --target test_selenium.py::test_selenium
Launching pytest with arguments test_selenium.py::test_selenium in /Users/yukuai/personal_project/Yu12ProTesting/test_selenium

============================= test session starts ==============================
platform darwin -- Python 3.7.6, pytest-5.4.2, py-1.8.1, pluggy-0.13.1 -- /Users/yukuai/Yu12ProTesting/bin/python
cachedir: .pytest_cache
rootdir: /Users/yukuai/personal_project/Yu12ProTesting/test_selenium
collecting ... 
test_selenium.py:None (test_selenium.py)
ImportError while importing test module '/Users/yukuai/personal_project/Yu12ProTesting/test_selenium/test_selenium.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../../Yu12ProTesting/lib/python3.7/site-packages/_pytest/python.py:511: in _importtestmodule
    mod = self.fspath.pyimport(ensuresyspath=importmode)
../../../Yu12ProTesting/lib/python3.7/site-packages/py/_path/local.py:701: in pyimport
    __import__(modname)
../../../Yu12ProTesting/lib/python3.7/site-packages/_pytest/assertion/rewrite.py:152: in exec_module
    exec(co, module.__dict__)
test_selenium.py:11: in <module>
    from selenium import webdriver
../../../Yu12ProTesting/lib/python3.7/site-packages/selenium/webdriver/__init__.py:18: in <module>
    from .firefox.webdriver import WebDriver as Firefox  # noqa
../../../Yu12ProTesting/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py:29: in <module>
    from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
../../../Yu12ProTesting/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py:27: in <module>
    from .remote_connection import RemoteConnection
../../../Yu12ProTesting/lib/python3.7/site-packages/selenium/webdriver/remote/remote_connection.py:24: in <module>
    import urllib3
../../../Yu12ProTesting/lib/python3.7/site-packages/urllib3/__init__.py:7: in <module>
    from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
../../../Yu12ProTesting/lib/python3.7/site-packages/urllib3/connectionpool.py:11: in <module>
    from .exceptions import (
../../../Yu12ProTesting/lib/python3.7/site-packages/urllib3/exceptions.py:2: in <module>
    from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead
../../../Yu12ProTesting/lib/python3.7/site-packages/urllib3/packages/six.py:199: in load_module
    mod = mod._resolve()
../../../Yu12ProTesting/lib/python3.7/site-packages/urllib3/packages/six.py:113: in _resolve
    return _import_module(self.mod)
../../../Yu12ProTesting/lib/python3.7/site-packages/urllib3/packages/six.py:82: in _import_module
    __import__(name)
E   ModuleNotFoundError: No module named 'http.client'
collected 0 items / 1 error

==================================== ERRORS ====================================
______________________ ERROR collecting test_selenium.py _______________________
ImportError while importing test module '/Users/yukuai/personal_project/Yu12ProTesting/test_selenium/test_selenium.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../../Yu12ProTesting/lib/python3.7/site-packages/_pytest/python.py:511: in _importtestmodule
    mod = self.fspath.pyimport(ensuresyspath=importmode)
../../../Yu12ProTesting/lib/python3.7/site-packages/py/_path/local.py:701: in pyimport
    __import__(modname)
../../../Yu12ProTesting/lib/python3.7/site-packages/_pytest/assertion/rewrite.py:152: in exec_module
    exec(co, module.__dict__)
test_selenium.py:11: in <module>
    from selenium import webdriver
../../../Yu12ProTesting/lib/python3.7/site-packages/selenium/webdriver/__init__.py:18: in <module>
    from .firefox.webdriver import WebDriver as Firefox  # noqa
../../../Yu12ProTesting/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py:29: in <module>
    from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
../../../Yu12ProTesting/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py:27: in <module>
    from .remote_connection import RemoteConnection
../../../Yu12ProTesting/lib/python3.7/site-packages/selenium/webdriver/remote/remote_connection.py:24: in <module>
    import urllib3
../../../Yu12ProTesting/lib/python3.7/site-packages/urllib3/__init__.py:7: in <module>
    from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
../../../Yu12ProTesting/lib/python3.7/site-packages/urllib3/connectionpool.py:11: in <module>
    from .exceptions import (
../../../Yu12ProTesting/lib/python3.7/site-packages/urllib3/exceptions.py:2: in <module>
    from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead
../../../Yu12ProTesting/lib/python3.7/site-packages/urllib3/packages/six.py:199: in load_module
    mod = mod._resolve()
../../../Yu12ProTesting/lib/python3.7/site-packages/urllib3/packages/six.py:113: in _resolve
    return _import_module(self.mod)
../../../Yu12ProTesting/lib/python3.7/site-packages/urllib3/packages/six.py:82: in _import_module
    __import__(name)
E   ModuleNotFoundError: No module named 'http.client'
=========================== short test summary info ============================
ERROR test_selenium.py
=============================== 1 error in 0.27s ===============================
ERROR: not found: /Users/yukuai/personal_project/Yu12ProTesting/test_selenium/test_selenium.py::test_selenium
(no name '/Users/yukuai/personal_project/Yu12ProTesting/test_selenium/test_selenium.py::test_selenium' in any of [<Module test_selenium.py>])

报这个错一般来说就是你项目里的包名和官方/第三方库的包名冲突导致没法调用到正确的包 比如你这个说是http.client没调到,多半是因为你项目里有个文件夹叫http 影响了python的查找

可以了,项目中有个http的包,删除可以执行成功了,谢谢老师。