【发布时间】:2016-05-01 10:13:18
【问题描述】:
我的文件结构如下所示
project
src
__init__.py
main.py
module.py
secondary.py
test
test_module.py
模块.py
>import secondary
x = False
secondary.py
>pass
test_module.py
>from unittest import TestCase
from src import module
class ModuleTest(TestCase):
def test_module(self):
self.assertTrue(module.x)
在/project/ 中调用python3 -m unittest discover 会出错:
File "/Users/Me/Code/project/test/test_module.py", line 6, in <module>
from src import module
File "/Users/Me/Code/project/src/module.py", line 1, in <module>
import secondary
ImportError: No module named 'secondary'
我该怎么做才能正确导入secondary.py?
【问题讨论】:
-
你可以通过
import .secondary指定它在同一个目录中
标签: python unit-testing python-3.x python-unittest