Post-mortem debugging also works when there is a failure in layer
setup.

    >>> import os, shutil, sys, tempfile
    >>> tdir = tempfile.mkdtemp()
    >>> dir = os.path.join(tdir, 'TESTS-DIR')
    >>> os.mkdir(dir)
    >>> open(os.path.join(dir, 'tests.py'), 'w').write(
    ... '''
    ... import doctest
    ...
    ... class Layer:
    ...     @classmethod
    ...     def setUp(self):
    ...         x = 1
    ...         raise ValueError
    ...     
    ... def a_test():
    ...     """
    ...     >>> None
    ...     """
    ... def test_suite():
    ...     suite = doctest.DocTestSuite()
    ...     suite.layer = Layer
    ...     return suite
    ... 
    ... ''')
    
    >>> class Input:
    ...     def __init__(self, src):
    ...         self.lines = src.split('\n')
    ...     def readline(self):
    ...         line = self.lines.pop(0)
    ...         print line
    ...         return line+'\n'

    >>> real_stdin = sys.stdin
    >>> if sys.version_info[:2] == (2, 3):
    ...     sys.stdin = Input('n\np x\nc')
    ... else:
    ...     sys.stdin = Input('p x\nc')

    >>> sys.argv = [testrunner_script]
    >>> import zope.testing.testrunner
    >>> try:
    ...     zope.testing.testrunner.run_internal(['--path', dir, '-D'])
    ... finally: sys.stdin = real_stdin
    ... # doctest: +ELLIPSIS
    Running tests.Layer tests:
      Set up tests.Layer exceptions.ValueError:
    <BLANKLINE>
    > ...tests.py(8)setUp()
    -> raise ValueError
    (Pdb) p x
    1
    (Pdb) c
    True

Note that post-mortem debugging doesn't work when the layer is run in
a subprocess:

    >>> if sys.version_info[:2] == (2, 3):
    ...     sys.stdin = Input('n\np x\nc')
    ... else:
    ...     sys.stdin = Input('p x\nc')

    >>> open(os.path.join(dir, 'tests2.py'), 'w').write(
    ... '''
    ... import doctest, unittest
    ...
    ... class Layer1:
    ...     @classmethod
    ...     def setUp(self):
    ...         pass
    ...
    ...     @classmethod
    ...     def tearDown(self):
    ...         raise NotImplementedError
    ...
    ... class Layer2:
    ...     @classmethod
    ...     def setUp(self):
    ...         x = 1
    ...         raise ValueError
    ...     
    ... def a_test():
    ...     """
    ...     >>> None
    ...     """
    ... def test_suite():
    ...     suite1 = doctest.DocTestSuite()
    ...     suite1.layer = Layer1
    ...     suite2 = doctest.DocTestSuite()
    ...     suite2.layer = Layer2
    ...     return unittest.TestSuite((suite1, suite2))
    ... 
    ... ''')

    >>> import sys
    >>> try:
    ...     zope.testing.testrunner.run_internal(
    ...       ['--path', dir, '-Dvv', '--tests-pattern', 'tests2'])
    ... finally: sys.stdin = real_stdin
    ... # doctest: +ELLIPSIS +REPORT_NDIFF
    Running tests at level 1
    Running tests2.Layer1 tests:
      Set up tests2.Layer1 in 0.000 seconds.
      Running:
     a_test (tests2)
      Ran 1 tests with 0 failures and 0 errors in 0.001 seconds.
    Running tests2.Layer2 tests:
      Tear down tests2.Layer1 ... not supported
      Running in a subprocess.
      Set up tests2.Layer2
    **********************************************************************
    <BLANKLINE>
    Can't post-mortem debug when running a layer as a subprocess!
    Try running layer 'tests2.Layer2' by itself.
    <BLANKLINE>
    **********************************************************************
    <BLANKLINE>
    Traceback (most recent call last):
    ...
        raise ValueError
    ValueError
    <BLANKLINE>
    <BLANKLINE>
    Tests with errors:
       runTest (zope.testing.testrunner.runner.SetUpLayerFailure)
    Total: 1 tests, 0 failures, 1 errors in 0.210 seconds.
    True

    >>> shutil.rmtree(tdir)

