1
Post-mortem debugging also works when there is a failure in layer
4
>>> import os, shutil, sys, tempfile
5
>>> tdir = tempfile.mkdtemp()
6
>>> dir = os.path.join(tdir, 'TESTS-DIR')
8
>>> open(os.path.join(dir, 'tests.py'), 'w').write(
23
... suite = doctest.DocTestSuite()
24
... suite.layer = Layer
30
... def __init__(self, src):
31
... self.lines = src.split('\n')
32
... def readline(self):
33
... line = self.lines.pop(0)
37
>>> real_stdin = sys.stdin
38
>>> if sys.version_info[:2] == (2, 3):
39
... sys.stdin = Input('n\np x\nc')
41
... sys.stdin = Input('p x\nc')
43
>>> sys.argv = [testrunner_script]
44
>>> import zope.testing.testrunner
46
... zope.testing.testrunner.run(['--path', dir, '-D'])
47
... finally: sys.stdin = real_stdin
48
... # doctest: +ELLIPSIS
49
Running tests.Layer tests:
50
Set up tests.Layer exceptions.ValueError:
52
> ...tests.py(8)setUp()
59
Note that post-mortem debugging doesn't work when the layer is run in
62
>>> if sys.version_info[:2] == (2, 3):
63
... sys.stdin = Input('n\np x\nc')
65
... sys.stdin = Input('p x\nc')
67
>>> open(os.path.join(dir, 'tests2.py'), 'w').write(
69
... import doctest, unittest
77
... def tearDown(self):
78
... raise NotImplementedError
91
... suite1 = doctest.DocTestSuite()
92
... suite1.layer = Layer1
93
... suite2 = doctest.DocTestSuite()
94
... suite2.layer = Layer2
95
... return unittest.TestSuite((suite1, suite2))
100
... zope.testing.testrunner.run(
101
... ['--path', dir, '-Dvv', '--tests-pattern', 'tests2'])
102
... finally: sys.stdin = real_stdin
103
... # doctest: +ELLIPSIS
104
Running tests at level 1
105
Running tests2.Layer1 tests:
106
Set up tests2.Layer1 in 0.000 seconds.
109
Ran 1 tests with 0 failures and 0 errors in 0.001 seconds.
110
Running tests2.Layer2 tests:
111
Tear down tests2.Layer1 ... not supported
112
Running in a subprocess.
114
**********************************************************************
116
Can't post-mortem debug when running a layer as a subprocess!
117
Try running layer 'tests2.Layer2' by itself.
119
**********************************************************************
121
Traceback (most recent call last):
128
runTest (__main__.SetUpLayerFailure)
129
Total: 1 tests, 0 failures, 1 errors in 0.210 seconds.
132
>>> shutil.rmtree(tdir)