pytest ImportError

时间:2019-02-16 19:48:27

标签: python pytest

我的文件夹布局大致是这样

mesa/
    └── mesa
        └── __init__.py
        └── some module files
    └── tests

当我在最上方的mesa文件夹中运行pytest --cov=mesa tests/时,收到以下错误消息(仅是摘录)

==================================== ERRORS ====================================
__________________ ERROR collecting tests/test_batchrunner.py __________________
ImportError while importing test module '/Users/kumom/Documents/Projects/mesa/tests/test_batchrunner.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_batchrunner.py:8: in <module>
    from mesa import Agent, Model
E   ImportError: cannot import name 'Agent'

即使存在__init__.py文件,为什么还会发生这种情况?

1 个答案:

答案 0 :(得分:0)

它可能尝试从最上方的mesa /而不是从mesa / mesa /

导入