title: How to use pdb.set_trace() in a Django unittest?
body: <p>I want to debug a Django TestCase just like I would any other Python code:  Simply call <code>pdb.set_trace()</code> and then drop into an interactive session.  When I do that, I don't see anything, as the tests are run in a different process.  I'm using <a href="https://github.com/jezdez/django-discover-runner#django-discover-runner" rel="noreferrer">django-discover-runner</a>, but my guess is that this applies to the default Django test runner.</p>
  
  <h3>The question:</h3>
  
  <p>Is it possible to drop into a <code>pdb</code> session while using <code>django-discover-runner</code> a) on every error / fail, AND/OR b) only when I call <code>pdb.set_trace()</code> in my test code?</p>
  
  <h3>Some research:</h3>
  
  <p><a href="https://stackoverflow.com/a/16103544/785400">This answer</a> explains that Django creates another process, and suggests using a call to <code>rpdb2 debugger</code>, a part of <code>winpdb</code>, but I don't want to use <code>winpdb</code>, I'd rather use <code>ipdb</code>.</p>
  
  <p><a href="https://stackoverflow.com/a/1239545/785400">This answer</a> solves the problem for <code>django-nose</code> by running the test command like this: <code>./manage.py test -- -s</code>, but that option's not available for <code>django-discover-runner</code>.</p>
  
  <p><a href="https://stackoverflow.com/a/3517646/785400">This answer</a> shows that I can do this with <code>ipython</code>:</p>
  
  <pre><code>In [9]: %pdb
  Automatic pdb calling has been turned ON
  </code></pre>
  
  <p>That seems like a potential option, but it seems a bit cumbersome to fire up <code>ipython</code> every time I run tests.</p>
  
  <p>Finally, <a href="https://stackoverflow.com/a/6012325/785400">this answer</a> shows that <code>nose</code> comes with a <code>--pdb</code> flag that drops into <code>pdb</code> on errors, which is what I want.  Is my only option to switch to the <code>django-nose</code> test runner?</p>
  
  <p>I don't see any options for this in the built-in help for <code>django-discover-runner</code>:</p>
  
  <pre><code>$ python manage.py help test --settings=settings.test
  Usage: manage.py test [options] [appname ...]
  
  Runs the test suite for the specified applications, or the entire site if no apps are specified.
  
  Options:
    -v VERBOSITY, --verbosity=VERBOSITY
                          Verbosity level; 0=minimal output, 1=normal output,
                          2=verbose output, 3=very verbose output
    --settings=SETTINGS   The Python path to a settings module, e.g.
                          "myproject.settings.main". If this isn't provided, the
                          DJANGO_SETTINGS_MODULE environment variable will be
                          used.
    --pythonpath=PYTHONPATH
                          A directory to add to the Python path, e.g.
                          "/home/djangoprojects/myproject".
    --traceback           Print traceback on exception
    --noinput             Tells Django to NOT prompt the user for input of any
                          kind.
    --failfast            Tells Django to stop running the test suite after
                          first failed test.
    --testrunner=TESTRUNNER
                          Tells Django to use specified test runner class
                          instead of the one specified by the TEST_RUNNER
                          setting.
    --liveserver=LIVESERVER
                          Overrides the default address where the live server
                          (used with LiveServerTestCase) is expected to run
                          from. The default value is localhost:8081.
    -t TOP_LEVEL, --top-level-directory=TOP_LEVEL
                          Top level of project for unittest discovery.
    -p PATTERN, --pattern=PATTERN
                          The test matching pattern. Defaults to test*.py.
    --version             show program's version number and exit
    -h, --help            show this help message and exit
  </code></pre>