【发布时间】:2018-07-05 13:44:20
【问题描述】:
假设我在foo.py 中有以下代码:
def start():
"""
>>> start()
Hello world
"""
test = 10
print('Hello world')
通常,我会通过在终端中运行 pytest foo.py --doctest-modules -v 来运行 doctest。相反,我希望能够通过 Visual Studio Code 的内置调试器对其进行测试,以跟踪变量和调用堆栈。
我项目的launch.json中有如下配置:
"name": "PyTest",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config:python.pythonPath}",
"module": "pytest",
"args": [
"${file}",
"--doctest-modules",
"-v"
],
"cwd": "${workspaceRoot}",
"env": {},
"envFile": "${workspaceRoot}/.env",
"debugOptions": [
"RedirectOutput"
]
但是,当我打开文件并在 VSCode 调试器中运行 PyTest 调试配置时,文档测试仅在内置终端中运行 - 调试器面板中没有显示任何内容。我应该如何配置调试器才能使用其变量和调用堆栈?
【问题讨论】:
-
很遗憾,我无法重现您的问题。在我安装 pytest 并将您的配置复制到
launch.json之后,一切正常,并且我可以在 doctest 运行期间成功暂停断点。可能是由 VSC/extension/pytest 中的临时错误引起的? -
非常感谢@Oliver Leung!!!我正在寻找 Python Doctests VSCode
launch.json2 天 :) 它对我有用,但必须删除几个无效参数,如pythonPath和debugOptions。我在 WSL 1 上使用 VSCode 1.52.1
标签: python visual-studio-code pytest docstring doctest