title: Debug Pytest in docker container using VS Code
body: <p>I have troubles to setup debugging of py.test code in docker container using VS Code.</p>
  
  <p>After studying this: <a href="https://code.visualstudio.com/docs/python/debugging" rel="noreferrer">https://code.visualstudio.com/docs/python/debugging</a>
  And this: <a href="https://stackoverflow.com/questions/40233928/how-to-remote-debug-python-code-in-a-docker-container-with-vs-code">How to remote debug python code in a Docker Container with VS Code</a></p>
  
  <p>I have setup following debug configuration in vscode:</p>
  
  <pre><code>{
    "name": "Python: Attach",
    "type": "python",
    "request": "attach",
    "localRoot": "${workspaceFolder}",
    "remoteRoot": "/capi",
    "port": 3000,
    "secret": "secret_text",
    "host": "localhost"
  }
  </code></pre>
  
  <p>I have imported this bit into my test file:</p>
  
  <pre><code>import ptvsd
  ptvsd.enable_attach("secret_text", address = ('0.0.0.0', 3000))
  ptvsd.wait_for_attach()
  </code></pre>
  
  <p>And I made sure I open that 3000 port in docker-compose file:</p>
  
  <pre><code> ports:
        - 3000:3000
  </code></pre>
  
  <p>I double checked that the port is open:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>It seems to be the case. When I run pytest file from the container it starts and waits for debugger to be connected:</p>
  
  <pre><code>===================================================== 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  
  </code></pre>
  
  <p>But when I run this configuration from VS Code nothing seems to happen.</p>
  
  <p><a href="https://i.stack.imgur.com/WXFxC.png" rel="noreferrer"><img src="https://i.stack.imgur.com/WXFxC.png" alt="enter image description here"></a>
  It seems to hang. Nothing in the debug console or in the docker container.</p>
  
  <p>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.</p>
  
  <p>Have anyone managed to do this? I would appreciate some help. </p>