ModulenotFoundError试图在VS代码上配置单元测试
我在同一目录中为模块添加了一个模块和一个测试文件,并希望从VS代码运行测试。但是,在配置VS代码以使用Python 3.8.3(Pyenv)并使用UniteSts时,测试资源管理器中存在错误,该错误指出错误发现UNITSEST测试的错误(请参阅输出> Python)
。
并在输出中Python
Failed to import test module: shared-scripts.utils.run_command_test
Traceback (most recent call last):
File "/Users/username/.pyenv/versions/3.8.13/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
module = self._get_module_from_name(name)
File "/Users/username/.pyenv/versions/3.8.13/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
__import__(name)
File "/file_path/shared-scripts/utils/run_command_test.py", line 2, in <module>
import run_command
ModuleNotFoundError: No module named 'run_command'
操作系统:MACOS 12.4(蒙特雷),Visual Studio代码:版本:1.68.1
启动。JSON
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true
}
]
}
设置。JSON
{
"python.testing.unittestArgs": [
"-v",
"-s",
".",
"-p",
"*test*.py"
],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
}
这在Pycharm Community Edition中正常工作,我不确定如何在VS代码上使用此功能。有什么建议吗?
I have added a module and a test file for the module in the same directory and want to run tests from VS Code. However, upon configuring VS Code to use Python 3.8.3 (pyenv) and to use unittests there is an error in the Test Explorer that states Error discovering unittest tests (see Output > Python)
.
And in Output > Python
Failed to import test module: shared-scripts.utils.run_command_test
Traceback (most recent call last):
File "/Users/username/.pyenv/versions/3.8.13/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
module = self._get_module_from_name(name)
File "/Users/username/.pyenv/versions/3.8.13/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
__import__(name)
File "/file_path/shared-scripts/utils/run_command_test.py", line 2, in <module>
import run_command
ModuleNotFoundError: No module named 'run_command'
Operating System: MacOS 12.4 (Monterey), Visual Studio Code: Version: 1.68.1
launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true
}
]
}
settings.json
{
"python.testing.unittestArgs": [
"-v",
"-s",
".",
"-p",
"*test*.py"
],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
}
This works fine in PyCharm Community Edition and I am unsure on how to get this working on VS Code. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论