我的项目层次结构是这样的
project
src
fruit_pkg
count_fruits.py
test
fruit_pkg
test_count_fruits.py
现在说在模块内部count_fruits.py我有一个名为addition. 为了测试addition,我是否必须count_fruits使用导入模块
my_mod = __import__("fruit_pkg.count_fruits")
cnt_fruit = getattr(my_mod,"count_fruits")
然后为我的测试做类似的事情
def my_test(self):
#some work happen here
cnt_fruit.addition(blah, blah)
#more work happen here
或者:由于src和test代码都在同一个包fruit_pkg中,有没有更简单的方法来访问里面的函数count_fruits。
对于并行,在 Java 中,如果 thesrc和 junit 测试代码都在同一个包中,则根本不需要导入。