I have troubles to setup debugging of py.test code in docker container using VS Code.
After studying this: https://code.visualstudio.com/docs/python/debugging And this: How to remote debug python code in a Docker Container with VS Code
I have setup following debug configuration in vscode:
{
"name": "Python: Attach",
"type": "python",
"request": "attach",
"localRoot": "${workspaceFolder}",
"remoteRoot": "/capi",
"port": 3000,
"secret": "secret_text",
"host": "localhost"
}
I have imported this bit into my test file:
import ptvsd
ptvsd.enable_attach("secret_text", address = ('0.0.0.0', 3000))
ptvsd.wait_for_attach()
And I made sure I open that 3000 port in docker-compose file:
ports:
- 3000:3000
I double checked that the port is open:
nmap -p 3000 localhost
Starting Nmap 7.60 ( https://nmap.org ) at 2018-07-19 10:53 CEST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000074s latency).
PORT STATE SERVICE
3000/tcp open ppp
Nmap done: 1 IP address (1 host up) scanned in 0.11 seconds
It seems to be the case. When I run pytest file from the container it starts and waits for debugger to be connected:
===================================================== test session starts =====================================================
platform linux2 -- Python 2.7.15, pytest-3.5.1, py-1.5.3, pluggy-0.6.0
rootdir: /capi, inifile:
plugins: requests-mock-1.5.0, xdist-1.14, metadata-1.7.0, html-1.16.1, cov-2.5.1
collecting 0 items
But when I run this configuration from VS Code nothing seems to happen.
It seems to hang. Nothing in the debug console or in the docker container.
I have setup remote debug for a simple hello-world.py console app just for testing and it seems to work. So my assumption is it has something to do with the fact that I'm trying to debug a pytest.
Have anyone managed to do this? I would appreciate some help.
