为什么我无法将本地项目模块导入到单元测试模块(Python3.9)中?
我有一个 Python 3.9 单元测试项目,它包含在 Visual Studio 2019CE 项目中。该项目需要以 Azure 数据工厂为目标。要与 Azure 数据工厂对话,需要将支持模块/类导入到单元测试模块中。将支持对象导入到单元测试模块中时,测试资源管理器将无法再发现该单元测试模块。
导入命令:
from tools.adf_client import ADFClient
我可以导入什么:
import pyodbc
有什么区别?
pyodbc
已安装和工具。 adf_client
不是,它是单元测试项目中的一个文件。
我尝试过的:
我尝试将一个空模块放在与单元测试模块相同的目录中,并将其导入到单元测试模块中。单元测试模块仍然不可发现。
我见过人们修改路径的例子。其他人评论说这不是一个好的做法。
可能的解决方案:
在单元测试项目执行之前创建一个setup.py
并将支持包安装到环境中。这假设问题是未安装该模块。
I have a unit test project in Python 3.9 which is contained within a Visual Studio 2019CE project. This project needs to target Azure Data Factory. To talk to Azure Data Factory there is supporting modules/classes that need to be imported into the unit test module. When importing the supporting objects into a unit test module, the unit test module is no longer discoverable by test explorer.
Import command:
from tools.adf_client import ADFClient
What can I import:
import pyodbc
What is the difference?
pyodbc
is installed and tools.adf_client
is not, it is a file in the unit test project.
What I have tried:
I tried putting an empty module in the same directory as the unit test module and importing that into the unit test module. The unit test module is still not discoverable.
I have seen examples of people modifying the path. Other people have commented that this is not good practice.
Possible solution:
Creating a setup.py
and installing supporting packages into the environment prior to unit-test project execution. This assumes that the problem is that the module is not installed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论