【发布时间】:2023-10-15 23:23:01
【问题描述】:
1.环境
我正在使用 Anaconda/Spyder 工具在 Windows 10 中工作。 我有一个 python 项目组织如下。
folder_project
test_all.py
folder_utils
__init__.py
function1.py
folder_tests
__init__.py
test_function1.py
init.py 文件是空文件。 实现代码覆盖率的基本想法(也许可以改进方法)是:
- 一个 python 文件以不同方式测试一个函数
-
test_function1.py 将包含每个测试的一个函数:
def test_001(): ...
test_all.py 文件将调用所有 test_functionXXX.py 文件的所有函数
在 Spyder 中,我注意在 PYTHONPATH 中添加 folder_project。
2。问题
我在导入 folder_tests 包时遇到错误...
我在 test_all.py 中有
import folder_tests.test_function1
def main():
# Testing function1
test_function1.test001()
我收到以下错误:
ModuleNotFoundError: No module named 'folder_tests.test_function1'
如果我这样做
import folder_tests
我没有错误消息,但是我对此无能为力...
如果我在中更改导入语句
from folder_tests import test_function1
我收到以下错误:
ImportError: cannot import name 'test_function1' from 'folder_tests'
请问您知道我该如何纠正吗?
提前感谢您的帮助!
最佳,
皮埃罗
【问题讨论】:
标签: python module package importerror