小编Pav*_*l K的帖子

使用 VS Code 在 docker 容器中调试 Pytest

我在使用 VS Code 在 docker 容器中设置调试 py.test 代码时遇到了麻烦。

在研究了这个之后:https : //code.visualstudio.com/docs/python/debugging 还有这个:How to remote debug python code in a Docker Container with VS Code

我在 vscode 中设置了以下调试配置:

{
  "name": "Python: Attach",
  "type": "python",
  "request": "attach",
  "localRoot": "${workspaceFolder}",
  "remoteRoot": "/capi",
  "port": 3000,
  "secret": "secret_text",
  "host": "localhost"
}
Run Code Online (Sandbox Code Playgroud)

我已将此位导入到我的测试文件中:

import ptvsd
ptvsd.enable_attach("secret_text", address = ('0.0.0.0', 3000))
ptvsd.wait_for_attach()
Run Code Online (Sandbox Code Playgroud)

我确保我在 docker-compose 文件中打开了那个 3000 端口:

 ports:
      - 3000:3000
Run Code Online (Sandbox Code Playgroud)

我仔细检查了端口是否打开:

nmap -p 3000 localhost

Starting Nmap 7.60 ( https://nmap.org ) at 2018-07-19 10:53 CEST …
Run Code Online (Sandbox Code Playgroud)

pytest docker visual-studio-code vscode-debugger

7
推荐指数
1
解决办法
2256
查看次数