Python 新人第一帖,请教一下为什么 pycharm 无法导入同类的

乌云乌云快走开 · 2019年11月03日 · 最后由 Karaser 回复于 2019年11月04日 · 1326 次阅读

先说一下背景,我在执行 test_xueqiu.py 的时候提示错误,错误信息贴在下面. 实在是百度不出来了,所以才来社区请教的.烦请各位前辈为小弟指点一下迷津




错误信息在下面:

Testing started at 1:42 ...
D:\python_workSpace\Appium\venv\Scripts\python3.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.2\helpers\pycharm_jb_pytest_runner.py" --target test_xueqiu.py::TestXueqiu.test_add
Launching pytest with arguments test_xueqiu.py::TestXueqiu::test_add in D:\python_workSpace\Appium\test_appium_po\test_case

============================= test session starts =============================
platform win32 -- Python 3.6.5, pytest-5.1.2, py-1.8.0, pluggy-0.12.0
rootdir: D:\python_workSpace\Appium\test_appium_po\test_case
plugins: allure-pytest-2.8.0
test_xueqiu.py:None (test_xueqiu.py)
ImportError while importing test module 'D:\python_workSpace\Appium\test_appium_po\test_case\test_xueqiu.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
test_xueqiu.py:1: in
from test_appium_po.pages.main_page import MainPage
..\pages\main_page.py:4: in
from test_appium_po.pages.chose_page import ChosePage
..\pages\chose_page.py:2: in
from test_appium_po.pages.main_page import MainPage
E ImportError: cannot import name 'MainPage'
collected 0 items / 1 errors

=================================== ERRORS ====================================
_______________________ ERROR collecting test_xueqiu.py _______________________
ImportError while importing test module 'D:\python_workSpace\Appium\test_appium_po\test_case\test_xueqiu.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
test_xueqiu.py:1: in
from test_appium_po.pages.main_page import MainPage
..\pages\main_page.py:4: in
from test_appium_po.pages.chose_page import ChosePage
..\pages\chose_page.py:2: in
from test_appium_po.pages.main_page import MainPage
E ImportError: cannot import name 'MainPage'
============================== 1 error in 0.30s ===============================
ERROR: not found: D:\python_workSpace\Appium\test_appium_po\test_case\test_xueqiu.py::TestXueqiu::test_add
(no name 'D:\python_workSpace\Appium\test_appium_po\test_case\test_xueqiu.py::TestXueqiu::test_add' in any of [])

共收到 2 条回复 时间 点赞

实在是百度不出来

😂 你都百度了啥。。。。百度下 “python 循环导入” 吧

MainPage 删掉 ChosePage 的引用吧

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册