【发布时间】:2014-08-04 07:52:08
【问题描述】:
我有一个包和一个测试包。根据Where do the Python unit tests go? 的建议,测试应该在不同的目录中。项目的目录树如下:
project\
kernel\
__init__.py
file1.py
file2.py
tests\
__init__.py
test1.py
test2.py
test3.py
我想将kernel 包导入tests 包,因为这是测试file1.py 和file2.py 的地方。另外,我想在__init__.py 中使用一个import 语句,而不是在每个测试中一次又一次地导入kernel。
我尝试将以下内容添加到 tests 和 test2.py 、 test2.py 中的 __init__.py 文件中(一起和分别),但没有成功(第一个没有害处,第二个给出语法错误):
import kernel
import ../kernel
我正在使用 python2.6。从命令行发生上述所有事情。当我使用 Eclipse PyDev 时,一切都很神奇。
【问题讨论】:
标签: python unit-testing testing