【发布时间】:2020-10-12 17:55:53
【问题描述】:
配置:
我正在使用以下版本的 VSCode:
Version: 1.46.1
Commit: cd9ea6488829f560dc949a8b2fb789f3cdc05f5d
Date: 2020-06-17T21:13:08.304Z
Electron: 7.3.1
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Linux x64 5.3.0-59-generic snap
使用 Python 扩展 ms-python.python 版本 v2020.6.8。唯一安装的 PIP 是:
Package Version
----------------- -------
astroid 2.4.2
attrs 19.3.0
autopep8 1.5.3
isort 4.3.21
lazy-object-proxy 1.4.3
mccabe 0.6.1
more-itertools 8.4.0
packaging 20.4
pip 20.1.1
pluggy 0.13.1
py 1.8.2
pycodestyle 2.6.0
pylint 2.5.3
pyparsing 2.4.7
pytest 5.4.3
setuptools 47.1.1
six 1.15.0
toml 0.10.1
wcwidth 0.2.4
wheel 0.34.2
wrapt 1.12.1
问题:
我正在尝试在 vscode 中调试我的 python 测试,但在调试控制台中出现以下错误:
============================= test session starts ==============================
platform linux -- Python 3.8.3, pytest-5.4.3, py-1.8.2, pluggy-0.13.1
rootdir: /workspaces/test_python_debugging
collected 0 items / 1 error
==================================== ERRORS ====================================
_________________ ERROR collecting tst/dummy/test_unit_math.py _________________
ImportError while importing test module '/workspaces/test_python_debugging/tst/dummy/test_unit_math.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tst/dummy/test_unit_math.py:5: in <module>
from dummy.math import add
E ModuleNotFoundError: No module named 'dummy'
--------------- generated xml file: /tmp/tmp-188wLObs4r6II9x.xml ---------------
=========================== short test summary info ============================
ERROR tst/dummy/test_unit_math.py
=============================== 1 error in 0.19s ===============================
ERROR: not found: /workspaces/test_python_debugging/tst/dummy/test_unit_math.py::test_addition
(no name '/workspaces/test_python_debugging/tst/dummy/test_unit_math.py::test_addition' in any of [<Module tst/dummy/test_unit_math.py>])
测试本身在终端中运行良好。换句话说,找不到“丢失的”模块没有问题。示例:
0f617e2a72ee [/workspaces/test_python_debugging]$ python -m pytest tst/**/te
st*.py -k test_addition
=========================== test session starts ============================
platform linux -- Python 3.8.3, pytest-5.4.3, py-1.8.2, pluggy-0.13.1
rootdir: /workspaces/test_python_debugging
collected 1 item
tst/dummy/test_unit_math.py . [100%]
============================ 1 passed in 0.01s =============================
0f617e2a72ee [/workspaces/test_python_debugging]$
我启动调试器的方式是单击给定测试的Debug Test 链接。示例:
下面是正在使用的.devcontainer.json 配置:
{
"image": "test_python_debugging",
"extensions": [
"ms-python.python"
],
"mounts": [
"source=${localWorkspaceFolder},target=/app,type=bind,consistency=cached"
],
"settings": {
"terminal.integrated.shell.linux": "/bin/ash",
"terminal.integrated.shellArgs.linux": [
"-l"
],
"python.testing.pytestArgs": [
"tst",
"-k test_unit"
],
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true,
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.pythonPath": "/usr/local/bin/python"
},
"containerUser": "app",
"containerEnv": {
"PYTHONPATH": "/app/src"
}
}
有人知道我在配置方面缺少什么吗?
【问题讨论】:
-
你的工作空间的文件布局是什么,你是如何执行代码的?
-
@BrettCannon:如描述中所述,我正在通过 IDE 中测试上方显示的“调试测试”链接执行代码。我的提供由
/src 中的源代码和 /tst 中的测试代码构成。
标签: python visual-studio-code vscode-debugger