试图让这些最统一的脚本运行,但在每个脚本上,我都得到了标题中列出的ModuleNotFoundError。具体来说,全部3次返回
'No module named 'pan_tilt_unit''
我正在一个Docker容器中运行这个应用程序。
我的项目的结构是:
src/
pan_tilt_unit/
__init__.py
device_handler/
__init__.py
other_files.py
messages/
mqtt/
tests/
test1.py
test2.py
test3.py
run.py例如,在一个test.py文件中,我在顶部有:
from unittest import TestCase, main
from typing import List
from pan_tilt_unit.device_handler import *它在第三条导入语句上失败。不管我是在本地还是在容器内部运行文件,我都会得到这个错误。
我尝试过的事情:
添加了一个init.py文件。
我使用以下命令运行一个单独的测试文件
python3 -m unittest <filename>.py发布于 2022-03-09 08:22:09
在从test文件夹中运行测试时,需要从src/ like:python3 -m unittest ./tests/<filename>.py中运行unittest命令,或者在pythonpath中添加pan_tilt_unit。我会和前者一起去。
https://stackoverflow.com/questions/71404993
复制相似问题