title: VS Code / Python / Debugging pytest Test with the Debugger
body: <p>How can I get VS Code to put me into the debugger at the point of failure when running tests with pytest?</p>
  <p>Pytest catches all errors and asserts, and VS code invokes the debugger only on uncaught errors (I can change this to raised exception, but then it stops on everything raised under a try).</p>
  <p>I tried to set <code>--pdb</code> as pytest argument, but this leads to errors:</p>
  <pre><code>============================= test session starts =============================
  platform win32 -- Python 3.8.1, pytest-5.3.2, py-1.8.1, pluggy-0.13.1
  rootdir: c:\Projects\debugtest, inifile: pytest.ini
  collected 1 item
  
  test.py F
  &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; traceback &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
  Traceback (most recent call last):
    File &quot;C:\Projects\debugtest\test.py&quot;, line 4, in test_with_assert
      assert 42==2.71828
  AssertionError: assert 42 == 2.71828
  &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; entering PDB &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
  
  &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; PDB post_mortem (IO-capturing turned off) &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
  &gt; c:\projects\debugtest\test.py(4)test_with_assert()
  -&gt; assert 42==2.71828
  (Pdb)
  
  PYDEV DEBUGGER WARNING:
  sys.settrace() should not be used when the debugger is being used.
  This may cause the debugger to stop working correctly.
  If this is needed, please check: 
  http://pydev.blogspot.com/2007/06/why-cant-pydev-debugger-work-with.html
  to see how to restore the debug tracing back correctly.
  Call Location:
    File &quot;C:\Program Files\Python38\lib\bdb.py&quot;, line 359, in set_quit
      sys.settrace(None)
  
  
  - generated xml file: C:\Users\tzhgfma1\AppData\Local\Temp\tmp-24044mEWMyB1nPYAu.xml -
  !!!!!!!!!!!!!!!!!! _pytest.outcomes.Exit: Quitting debugger !!!!!!!!!!!!!!!!!!!
  ============================== 1 failed in 0.43s ==============================
  </code></pre>
  <p>I have a very simple project for testing this:</p>
  <p>.vscode\settings.json</p>
  <pre><code>{
      &quot;python.testing.pytestArgs&quot;: [
          &quot;--pdb&quot;
      ],
      &quot;python.testing.unittestEnabled&quot;: false,
      &quot;python.testing.nosetestsEnabled&quot;: false,
      &quot;python.testing.pytestEnabled&quot;: true,
      &quot;git.ignoreLimitWarning&quot;: false
  }
  </code></pre>
  <p>.vscode\launch.json</p>
  <pre><code>{
      // Use IntelliSense to learn about possible attributes.
      // Hover to view descriptions of existing attributes.
      // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
      &quot;version&quot;: &quot;0.2.0&quot;,
      &quot;configurations&quot;: [
          
          
          {
              &quot;name&quot;: &quot;Python: Current File&quot;,
              &quot;type&quot;: &quot;python&quot;,
              &quot;request&quot;: &quot;launch&quot;,
              &quot;program&quot;: &quot;${file}&quot;,
              &quot;console&quot;: &quot;internalConsole&quot;,
              &quot;justMyCode&quot;:false
          },
          {
              &quot;name&quot;: &quot;Python: Attach using Process Id&quot;,
              &quot;type&quot;: &quot;python&quot;,
              &quot;request&quot;: &quot;attach&quot;,
              &quot;processId&quot;: &quot;${command:pickProcess}&quot;,
              &quot;justMyCode&quot;: false
          },
          {
              &quot;name&quot;: &quot;Debug Tests&quot;,
              &quot;type&quot;: &quot;python&quot;,
              &quot;request&quot;: &quot;test&quot;,
              &quot;console&quot;: &quot;internalConsole&quot;,
              &quot;justMyCode&quot;: false
          }
      ]
  }
  </code></pre>
  <p>pytest.ini</p>
  <pre><code>[pytest]
  
  python_files = test*.py
  python_classes = Test
  python_functions = test
  addopts = --tb=native
  console_output_style = classic
  junit_duration_report = call
  filterwarnings =
      ignore::RuntimeWarning
  </code></pre>
  <p>and test.py:</p>
  <pre><code>def test_with_assert():
      assert 42==2.71828
  </code></pre>
  <p>Is <code>--pdb</code> the correct way to do this? Or how do I enter the debugger upon an assert or error?</p>