【发布时间】:2017-01-11 19:34:00
【问题描述】:
我在 tommy/core/tests/test_tprotocol.py 中编写了一些单元测试,在这个文件中,我有这一行:
from tommy.core.tprotocol import TRequest
但是当我在测试文件夹中运行 unittest 时:
python -m unittest tprotocol
我有一个 ImportError :
E
======================================================================
ERROR: tprotocol (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: tprotocol
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/loader.py", line 153, in loadTestsFromName
module = __import__(module_name)
ModuleNotFoundError: No module named 'tprotocol'
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (errors=1)
当我从子文件夹导入模块时,我总是遇到这种类型的错误... 解决这个问题的最佳方法是什么?
但如果我这样做python -m unittest tommy/core/tests/test_tprotocol.py,一切都会正常工作
【问题讨论】:
标签: python unit-testing import