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

xiaoxiao · July 30, 2019 · Last by xiaoxiao replied at August 07, 2019 · 392 hits

在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 条回复 时间 点赞

重建工程,已解决

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up