python unittest ImportError: Failed to import test module:

├── test
│   └── appender_test.py
├── utils
│   ├── appender.py
│   └── __init__.py
from utils.appender import Appender
import unittest

class AppenderTest(unittest.TestCase):
    def test_GetFileNameByNow(self):
        result=Appender.getFileNameByNow()
        print(result)
        self.assertEqual(result,"2017-12-14 17:00:00.csv")

使用unittest测试时发生错误,请问如何修改:

zjw at monster in ~/project/python/AdFetchExtractor/test (develop●) 
$ python3 -m unittest appender_test.py 
E
======================================================================
ERROR: appender_test (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: appender_test
Traceback (most recent call last):
  File "/usr/lib/python3.6/unittest/loader.py", line 153, in loadTestsFromName
    module = __import__(module_name)
  File "/home/zjw/project/python/AdFetchExtractor/test/appender_test.py", line 3, in <module>
    from utils.appender import Appender
ModuleNotFoundError: No module named 'utils'


----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (errors=1)
阅读 10.2k
1 个回答

你需要把utils的路径加到python的搜索路径中啊。比如sys.path.append('xxx')

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏