Python 执行 pytest 时报错 Hint: make sure your test modules/packages have valid Python names.

xiaoxiao · 2019年07月30日 · 最后由 xiaoxiao 回复于 2019年08月07日 · 2999 次阅读

在 UI 自动化框架工程目录下执行pytest时报错如下:

_________________________________________________ ERROR collecting test_cases/test_filming_and_upload_page/test_filming_page.py __________________________________________________
ImportError while importing test module '/Users/xxx/Projects/Python/py_uiautomator2/test_cases/test_filming_and_upload_page/test_filming_page.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
test_cases/test_filming_and_upload_page/test_filming_page.py:9: in <module>
    from common.app_engine import AppEngine
E   ModuleNotFoundError: No module named 'common'

工程结构如下:

  • py_uiautomator2
    • common
      • app_engine.py(class AppEngine())
    • pages
    • page_objects
    • test_cases
      • test_filming_and_upload_page
        • test_filming_page.py(class TestFilmingPage())

test_filming_page.py 的引用代码如下:

在 PyCharm 中右键直接 run 文件 test_filming_page.py 没有问题,而在/Users/xxx/Projects/Python/py_uiautomator2/目录下,直接执行pytest时就会报错,不知道怎么回事呢?有人遇到过执行pytest找不到包引用的情况吗?

共收到 1 条回复 时间 点赞

重建工程,已解决

需要 登录 後方可回應,如果你還沒有帳號按這裡 注册