├── 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)
你需要把utils的路径加到python的搜索路径中啊。比如sys.path.append('xxx')