This file is indexed.

/usr/share/pyshared/zope/testrunner/testrunner-edge-cases.txt 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
testrunner Edge Cases
=====================

This document has some edge-case examples to test various aspects of
the test runner.

Separating Python path and test directories
-------------------------------------------

The --path option defines a directory to be searched for tests *and* a
directory to be added to Python's search path.  The --test-path option
can be used when you want to set a test search path without also
affecting the Python path:

    >>> import os, sys
    >>> directory_with_tests = os.path.join(this_directory, 'testrunner-ex')

    >>> from zope import testrunner

    >>> defaults = [
    ...     '--test-path', directory_with_tests,
    ...     '--tests-pattern', '^sampletestsf?$',
    ...     ]
    >>> sys.argv = ['test']
    >>> testrunner.run_internal(defaults)
    ... # doctest: +ELLIPSIS
    Test-module import failures:
    <BLANKLINE>
    Module: sampletestsf
    <BLANKLINE>
    Traceback (most recent call last):
    ImportError: No module named sampletestsf
    ...

    >>> sys.path.append(directory_with_tests)
    >>> sys.argv = ['test']
    >>> testrunner.run_internal(defaults)
    ... # doctest: +ELLIPSIS
    Running samplelayers.Layer1 tests:
      Set up samplelayers.Layer1 in 0.000 seconds.
      Ran 9 tests with 0 failures and 0 errors in 0.000 seconds.
    ...
    Running zope.testrunner.layer.UnitTests tests:
      Tear down samplelayers.Layer122 in N.NNN seconds.
      Tear down samplelayers.Layer12 in N.NNN seconds.
      Tear down samplelayers.Layer1 in N.NNN seconds.
      Set up zope.testrunner.layer.UnitTests in N.NNN seconds.
      Ran 156 tests with 0 failures and 0 errors in N.NNN seconds.
    Tearing down left over layers:
      Tear down zope.testrunner.layer.UnitTests in N.NNN seconds.
    Total: 321 tests, 0 failures, 0 errors in N.NNN seconds.
    False

Bug #251759: The test runner's protection against descending into non-package
directories was ineffective, e.g. picking up tests from eggs that were stored
close by:

    >>> directory_with_tests = os.path.join(this_directory, 'testrunner-ex-251759')

    >>> defaults = [
    ...     '--test-path', directory_with_tests,
    ...     ]
    >>> testrunner.run_internal(defaults)
    Total: 0 tests, 0 failures, 0 errors in 0.000 seconds.
    False


Debugging Edge Cases
--------------------

    >>> directory_with_tests = os.path.join(this_directory, 'testrunner-ex')
    >>> defaults = [
    ...     '--test-path', directory_with_tests,
    ...     '--tests-pattern', '^sampletestsf?$',
    ...     ]
    >>> 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

Using pdb.set_trace in a function called by an ordinary test:

    >>> sys.stdin = Input('p x\nc')
    >>> sys.argv = ('test -ssample3 --tests-pattern ^sampletests_d$'
    ...             ' -t set_trace2').split()
    >>> try: testrunner.run_internal(defaults)
    ... finally: sys.stdin = real_stdin
    ... # doctest: +ELLIPSIS
    Running zope.testrunner.layer.UnitTests tests:...
    > testrunner-ex/sample3/sampletests_d.py(47)f()
    -> y = x
    (Pdb) p x
    1
    (Pdb) c
      Ran 1 tests with 0 failures and 0 errors in 0.001 seconds.
    ...
    False

Using pdb.set_trace in a function called by a doctest in a doc string:

    >>> sys.stdin = Input('n\np x\nc')
    >>> sys.argv = ('test -ssample3 --tests-pattern ^sampletests_d$'
    ...             ' -t set_trace4').split()
    >>> try: testrunner.run_internal(defaults)
    ... finally: sys.stdin = real_stdin
    Running zope.testrunner.layer.UnitTests tests:
      Set up zope.testrunner.layer.UnitTests in N.NNN seconds.
    > testrunner-ex/sample3/sampletests_d.py(NNN)f()
    -> y = x
    (Pdb) n
    --Return--
    > ...->None
    -> y = x
    (Pdb) p x
    1
    (Pdb) c
      Ran 1 tests with 0 failures and 0 errors in N.NNN seconds.
    Tearing down left over layers:
      Tear down zope.testrunner.layer.UnitTests in N.NNN seconds.
    False

Using pdb in a docstring-based doctest

    >>> sys.stdin = Input('n\np x\nc')
    >>> sys.argv = ('test -ssample3 --tests-pattern ^sampletests_d$'
    ...             ' -t set_trace3').split()
    >>> try: testrunner.run_internal(defaults)
    ... finally: sys.stdin = real_stdin
    Running zope.testrunner.layer.UnitTests tests:
      Set up zope.testrunner.layer.UnitTests in N.NNN seconds.
    > <doctest sample3.sampletests_d.set_trace3[1]>(3)?()
    -> y = x
    (Pdb) n
    --Return--
    > ...->None
    -> y = x
    (Pdb) p x
    1
    (Pdb) c
      Ran 1 tests with 0 failures and 0 errors in N.NNN seconds.
    Tearing down left over layers:
      Tear down zope.testrunner.layer.UnitTests in N.NNN seconds.
    False

Using pdb.set_trace in a doc file:


    >>> sys.stdin = Input('n\np x\nc')
    >>> sys.argv = ('test -ssample3 --tests-pattern ^sampletests_d$'
    ...             ' -t set_trace5').split()
    >>> try: testrunner.run_internal(defaults)
    ... finally: sys.stdin = real_stdin
    Running zope.testrunner.layer.UnitTests tests:
      Set up zope.testrunner.layer.UnitTests in N.NNN seconds.
    > <doctest set_trace5.txt[1]>(3)?()
    -> y = x
    (Pdb) n
    --Return--
    > ...->None
    -> y = x
    (Pdb) p x
    1
    (Pdb) c
      Ran 1 tests with 0 failures and 0 errors in N.NNN seconds.
    Tearing down left over layers:
      Tear down zope.testrunner.layer.UnitTests in N.NNN seconds.
    False

Using pdb.set_trace in a function called by a doctest in a doc file:


    >>> sys.stdin = Input('n\np x\nc')
    >>> sys.argv = ('test -ssample3 --tests-pattern ^sampletests_d$'
    ...             ' -t set_trace6').split()
    >>> try: testrunner.run_internal(defaults)
    ... finally: sys.stdin = real_stdin
    Running zope.testrunner.layer.UnitTests tests:
      Set up zope.testrunner.layer.UnitTests in N.NNN seconds.
    > testrunner-ex/sample3/sampletests_d.py(NNN)f()
    -> y = x
    (Pdb) n
    --Return--
    > ...->None
    -> y = x
    (Pdb) p x
    1
    (Pdb) c
      Ran 1 tests with 0 failures and 0 errors in N.NNN seconds.
    Tearing down left over layers:
      Tear down zope.testrunner.layer.UnitTests in N.NNN seconds.
    False

Post-mortem debugging function called from ordinary test:

    >>> sys.stdin = Input('p x\nc')
    >>> sys.argv = ('test -ssample3 --tests-pattern ^sampletests_d$'
    ...             ' -t post_mortem2 -D').split()
    >>> try: testrunner.run_internal(defaults)
    ... finally: sys.stdin = real_stdin
    ... # doctest: +NORMALIZE_WHITESPACE
    Running zope.testrunner.layer.UnitTests tests:...
    <BLANKLINE>
    <BLANKLINE>
    Error in test test_post_mortem2 (sample3.sampletests_d.TestSomething)
    Traceback (most recent call last):
      File "testrunner-ex/sample3/sampletests_d.py",
           line 37, in test_post_mortem2
        g()
      File "testrunner-ex/sample3/sampletests_d.py", line 46, in g
        raise ValueError
    ValueError
    <BLANKLINE>
    ...ValueError:
    <BLANKLINE>
    > testrunner-ex/sample3/sampletests_d.py(46)g()
    -> raise ValueError
    (Pdb) p x
    1
    (Pdb) c
    True


Post-mortem debugging docstring-based doctest:

    >>> sys.stdin = Input('p x\nc')
    >>> sys.argv = ('test -ssample3 --tests-pattern ^sampletests_d$'
    ...             ' -t post_mortem3 -D').split()
    >>> try: testrunner.run_internal(defaults)
    ... finally: sys.stdin = real_stdin
    ... # doctest: +NORMALIZE_WHITESPACE
    Running zope.testrunner.layer.UnitTests tests:
      Set up zope.testrunner.layer.UnitTests in N.NNN seconds.
    <BLANKLINE>
    <BLANKLINE>
    Error in test post_mortem3 (sample3.sampletests_d)
    Traceback (most recent call last):
    ...UnexpectedException: testrunner-ex/sample3/sampletests_d.py:NNN (2 examples)>
    <BLANKLINE>
    ...ValueError:
    <BLANKLINE>
    > <doctest sample3.sampletests_d.post_mortem3[1]>(1)?()
    (Pdb) p x
    1
    (Pdb) c
    True

Post-mortem debugging function called from docstring-based doctest:

    >>> sys.stdin = Input('p x\nc')
    >>> sys.argv = ('test -ssample3 --tests-pattern ^sampletests_d$'
    ...             ' -t post_mortem4 -D').split()
    >>> try: testrunner.run_internal(defaults)
    ... finally: sys.stdin = real_stdin
    ... # doctest: +NORMALIZE_WHITESPACE
    Running zope.testrunner.layer.UnitTests tests:
      Set up zope.testrunner.layer.UnitTests in N.NNN seconds.
    <BLANKLINE>
    <BLANKLINE>
    Error in test post_mortem4 (sample3.sampletests_d)
    Traceback (most recent call last):
    ...UnexpectedException: testrunner-ex/sample3/sampletests_d.py:NNN (1 example)>
    <BLANKLINE>
    ...ValueError:
    <BLANKLINE>
    > testrunner-ex/sample3/sampletests_d.py(NNN)g()
    -> raise ValueError
    (Pdb) p x
    1
    (Pdb) c
    True

Post-mortem debugging file-based doctest:

    >>> sys.stdin = Input('p x\nc')
    >>> sys.argv = ('test -ssample3 --tests-pattern ^sampletests_d$'
    ...             ' -t post_mortem5 -D').split()
    >>> try: testrunner.run_internal(defaults)
    ... finally: sys.stdin = real_stdin
    ... # doctest: +NORMALIZE_WHITESPACE
    Running zope.testrunner.layer.UnitTests tests:
      Set up zope.testrunner.layer.UnitTests in N.NNN seconds.
    <BLANKLINE>
    <BLANKLINE>
    Error testrunner-ex/sample3/post_mortem5.txt
    Traceback (most recent call last):
    ...UnexpectedException: testrunner-ex/sample3/post_mortem5.txt:0 (2 examples)>
    <BLANKLINE>
    ...ValueError:
    <BLANKLINE>
    > <doctest post_mortem5.txt[1]>(1)?()
    (Pdb) p x
    1
    (Pdb) c
    True



Post-mortem debugging function called from file-based doctest:

    >>> sys.stdin = Input('p x\nc')
    >>> sys.argv = ('test -ssample3 --tests-pattern ^sampletests_d$'
    ...             ' -t post_mortem6 -D').split()
    >>> try: testrunner.run_internal(defaults)
    ... finally: sys.stdin = real_stdin
    ... # doctest: +NORMALIZE_WHITESPACE
    Running zope.testrunner.layer.UnitTests tests:...
      Set up zope.testrunner.layer.UnitTests in N.NNN seconds.
    <BLANKLINE>
    <BLANKLINE>
    Error testrunner-ex/sample3/post_mortem6.txt
    Traceback (most recent call last):
      File ".../zope/testing/doctest/__init__.py", Line NNN, in debug
        runner.run(self._dt_test, clear_globs=False)
      File ".../zope/testing/doctest/__init__.py", Line NNN, in run
        r = DocTestRunner.run(self, test, compileflags, out, False)
      File ".../zope/testing/doctest/__init__.py", Line NNN, in run
        return self.__run(test, compileflags, out)
      File ".../zope/testing/doctest/__init__.py", Line NNN, in __run
        exc_info)
      File ".../zope/testing/doctest/__init__.py", Line NNN, in report_unexpected_exception
        raise UnexpectedException(test, example, exc_info)
    ...UnexpectedException: testrunner-ex/sample3/post_mortem6.txt:0 (2 examples)>
    <BLANKLINE>
    ...ValueError:
    <BLANKLINE>
    > testrunner-ex/sample3/sampletests_d.py(NNN)g()
    -> raise ValueError
    (Pdb) p x
    1
    (Pdb) c
    True

Post-mortem debugging of a docstring doctest failure:

    >>> sys.stdin = Input('p x\nc')
    >>> sys.argv = ('test -ssample3 --tests-pattern ^sampletests_d$'
    ...             ' -t post_mortem_failure2 -D').split()
    >>> try: testrunner.run_internal(defaults)
    ... finally: sys.stdin = real_stdin
    ... # doctest: +NORMALIZE_WHITESPACE
    Running zope.testrunner.layer.UnitTests tests:...
    <BLANKLINE>
    <BLANKLINE>
    Error in test post_mortem_failure2 (sample3.sampletests_d)
    <BLANKLINE>
    File "testrunner-ex/sample3/sampletests_d.py",
                   line 81, in sample3.sampletests_d.post_mortem_failure2
    <BLANKLINE>
    x
    <BLANKLINE>
    Want:
    2
    <BLANKLINE>
    Got:
    1
    <BLANKLINE>
    <BLANKLINE>
    > testrunner-ex/sample3/sampletests_d.py(81)_()
    ...ValueError:
    Expected and actual output are different
    > <string>(1)...()
    (Pdb) p x
    1
    (Pdb) c
    True


Post-mortem debugging of a docfile doctest failure:

    >>> sys.stdin = Input('p x\nc')
    >>> sys.argv = ('test -ssample3 --tests-pattern ^sampletests_d$'
    ...             ' -t post_mortem_failure.txt -D').split()
    >>> try: testrunner.run_internal(defaults)
    ... finally: sys.stdin = real_stdin
    ... # doctest: +NORMALIZE_WHITESPACE
    Running zope.testrunner.layer.UnitTests tests:...
    <BLANKLINE>
    <BLANKLINE>
    Error in test /home/jim/z3/zope.testrunner/src/zope/testing/testrunner-ex/sample3/post_mortem_failure.txt
    <BLANKLINE>
    File "testrunner-ex/sample3/post_mortem_failure.txt",
                                      line 2, in post_mortem_failure.txt
    <BLANKLINE>
    x
    <BLANKLINE>
    Want:
    2
    <BLANKLINE>
    Got:
    1
    <BLANKLINE>
    <BLANKLINE>
    > testrunner-ex/sample3/post_mortem_failure.txt(2)_()
    ...ValueError:
    Expected and actual output are different
    > <string>(1)...()
    (Pdb) p x
    1
    (Pdb) c
    True

Post-mortem debugging with triple verbosity

    >>> sys.argv = 'test --layer samplelayers.Layer1$ -vvv -D'.split()
    >>> testrunner.run_internal(defaults)
    Running tests at level 1
    Running samplelayers.Layer1 tests:
      Set up samplelayers.Layer1 in 0.000 seconds.
      Running:
        test_x1 (sampletestsf.TestA1) (0.000 s)
        test_y0 (sampletestsf.TestA1) (0.000 s)
        test_z0 (sampletestsf.TestA1) (0.000 s)
        test_x0 (sampletestsf.TestB1) (0.000 s)
        test_y1 (sampletestsf.TestB1) (0.000 s)
        test_z0 (sampletestsf.TestB1) (0.000 s)
        test_1 (sampletestsf.TestNotMuch1) (0.000 s)
        test_2 (sampletestsf.TestNotMuch1) (0.000 s)
        test_3 (sampletestsf.TestNotMuch1) (0.000 s)
      Ran 9 tests with 0 failures and 0 errors in 0.001 seconds.
    Tearing down left over layers:
      Tear down samplelayers.Layer1 in 0.000 seconds.
    False

Test Suites with None for suites or tests
-----------------------------------------

    >>> sys.argv = ['test',
    ...             '--tests-pattern', '^sampletests_none_suite$',
    ...     ]
    >>> testrunner.run_internal(defaults)
    Test-module import failures:
    <BLANKLINE>
    Module: sample1.sampletests_none_suite
    <BLANKLINE>
    Traceback (most recent call last):
    TypeError: Invalid test_suite, None, in sample1.sampletests_none_suite
    <BLANKLINE>
    <BLANKLINE>
    <BLANKLINE>
    Test-modules with import problems:
      sample1.sampletests_none_suite
    Total: 0 tests, 0 failures, 0 errors in N.NNN seconds.
    True


    >>> sys.argv = ['test',
    ...             '--tests-pattern', '^sampletests_none_test$',
    ...     ]
    >>> testrunner.run_internal(defaults)
    Test-module import failures:
    <BLANKLINE>
    Module: sample1.sampletests_none_test
    <BLANKLINE>
    Traceback (most recent call last):
    TypeError: ...
    <BLANKLINE>
    <BLANKLINE>
    <BLANKLINE>
    Test-modules with import problems:
      sample1.sampletests_none_test
    Total: 0 tests, 0 failures, 0 errors in N.NNN seconds.
    True

You must use --repeat with --report-refcounts
---------------------------------------------

It is an error to specify --report-refcounts (-r) without specifying a
repeat count greater than 1

    >>> sys.argv = 'test -r'.split()
    >>> testrunner.run_internal(defaults)
            You must use the --repeat (-N) option to specify a repeat
            count greater than 1 when using the --report_refcounts (-r)
            option.
    <BLANKLINE>
    True

    >>> sys.argv = 'test -r -N1'.split()
    >>> testrunner.run_internal(defaults)
            You must use the --repeat (-N) option to specify a repeat
            count greater than 1 when using the --report_refcounts (-r)
            option.
    <BLANKLINE>
    True