This file is indexed.

/usr/share/pyshared/zope/testrunner/testrunner-debugging-layer-setup.test is in python-zope.testrunner 4.0.3-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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)
    >>> written = 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
    >>> sys.stdin = Input('p x\nc')

    >>> sys.argv = [testrunner_script]
    >>> import zope.testrunner
    >>> try:
    ...     zope.testrunner.run_internal(['--path', dir, '-D'])
    ... finally: sys.stdin = real_stdin
    ... # doctest: +ELLIPSIS
    Running tests.Layer tests:
      Set up tests.Layer ...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:

    >>> sys.stdin = Input('p x\nc')

    >>> written = 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.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:
       Layer: tests2.Layer2
    Total: 1 tests, 0 failures, 1 errors in 0.210 seconds.
    True

    >>> shutil.rmtree(tdir)