~sidnei/zope3/ztk-1.0a1

« back to all changes in this revision

Viewing changes to src/zope/testing/testrunner-debugging-layer-setup.test

  • Committer: Thomas Hervé
  • Date: 2009-09-21 06:45:37 UTC
  • mfrom: (7.1.2 newer-zope-testing)
  • Revision ID: thomas@canonical.com-20090921064537-zcfyuv32hxj9eah0
Merge newer-zope-testing [a=sidnei] [f=429702] [r=therve,free.ekayanaka]

Update zope.testing to 3.8.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Post-mortem debugging also works when there is a failure in layer
2
 
setup.
3
 
 
4
 
    >>> import os, shutil, sys, tempfile
5
 
    >>> tdir = tempfile.mkdtemp()
6
 
    >>> dir = os.path.join(tdir, 'TESTS-DIR')
7
 
    >>> os.mkdir(dir)
8
 
    >>> open(os.path.join(dir, 'tests.py'), 'w').write(
9
 
    ... '''
10
 
    ... import doctest
11
 
    ...
12
 
    ... class Layer:
13
 
    ...     @classmethod
14
 
    ...     def setUp(self):
15
 
    ...         x = 1
16
 
    ...         raise ValueError
17
 
    ...     
18
 
    ... def a_test():
19
 
    ...     """
20
 
    ...     >>> None
21
 
    ...     """
22
 
    ... def test_suite():
23
 
    ...     suite = doctest.DocTestSuite()
24
 
    ...     suite.layer = Layer
25
 
    ...     return suite
26
 
    ... 
27
 
    ... ''')
28
 
    
29
 
    >>> class Input:
30
 
    ...     def __init__(self, src):
31
 
    ...         self.lines = src.split('\n')
32
 
    ...     def readline(self):
33
 
    ...         line = self.lines.pop(0)
34
 
    ...         print line
35
 
    ...         return line+'\n'
36
 
 
37
 
    >>> real_stdin = sys.stdin
38
 
    >>> if sys.version_info[:2] == (2, 3):
39
 
    ...     sys.stdin = Input('n\np x\nc')
40
 
    ... else:
41
 
    ...     sys.stdin = Input('p x\nc')
42
 
 
43
 
    >>> sys.argv = [testrunner_script]
44
 
    >>> import zope.testing.testrunner
45
 
    >>> try:
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:
51
 
    <BLANKLINE>
52
 
    > ...tests.py(8)setUp()
53
 
    -> raise ValueError
54
 
    (Pdb) p x
55
 
    1
56
 
    (Pdb) c
57
 
    True
58
 
 
59
 
Note that post-mortem debugging doesn't work when the layer is run in
60
 
a subprocess:
61
 
 
62
 
    >>> if sys.version_info[:2] == (2, 3):
63
 
    ...     sys.stdin = Input('n\np x\nc')
64
 
    ... else:
65
 
    ...     sys.stdin = Input('p x\nc')
66
 
 
67
 
    >>> open(os.path.join(dir, 'tests2.py'), 'w').write(
68
 
    ... '''
69
 
    ... import doctest, unittest
70
 
    ...
71
 
    ... class Layer1:
72
 
    ...     @classmethod
73
 
    ...     def setUp(self):
74
 
    ...         pass
75
 
    ...
76
 
    ...     @classmethod
77
 
    ...     def tearDown(self):
78
 
    ...         raise NotImplementedError
79
 
    ...
80
 
    ... class Layer2:
81
 
    ...     @classmethod
82
 
    ...     def setUp(self):
83
 
    ...         x = 1
84
 
    ...         raise ValueError
85
 
    ...     
86
 
    ... def a_test():
87
 
    ...     """
88
 
    ...     >>> None
89
 
    ...     """
90
 
    ... def test_suite():
91
 
    ...     suite1 = doctest.DocTestSuite()
92
 
    ...     suite1.layer = Layer1
93
 
    ...     suite2 = doctest.DocTestSuite()
94
 
    ...     suite2.layer = Layer2
95
 
    ...     return unittest.TestSuite((suite1, suite2))
96
 
    ... 
97
 
    ... ''')
98
 
 
99
 
    >>> try:
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.
107
 
      Running:
108
 
     a_test (tests2)
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.
113
 
      Set up tests2.Layer2
114
 
    **********************************************************************
115
 
    <BLANKLINE>
116
 
    Can't post-mortem debug when running a layer as a subprocess!
117
 
    Try running layer 'tests2.Layer2' by itself.
118
 
    <BLANKLINE>
119
 
    **********************************************************************
120
 
    <BLANKLINE>
121
 
    Traceback (most recent call last):
122
 
    ...
123
 
        raise ValueError
124
 
    ValueError
125
 
    <BLANKLINE>
126
 
    <BLANKLINE>
127
 
    Tests with errors:
128
 
       runTest (__main__.SetUpLayerFailure)
129
 
    Total: 1 tests, 0 failures, 1 errors in 0.210 seconds.
130
 
    True
131
 
 
132
 
    >>> shutil.rmtree(tdir)
133