4
If the --progress (-p) option is used, progress information is printed and
5
a carriage return (rather than a new-line) is printed between
6
detail lines. Let's look at the effect of --progress (-p) at different
9
>>> import os.path, sys
10
>>> directory_with_tests = os.path.join(this_directory, 'testrunner-ex')
12
... '--path', directory_with_tests,
13
... '--tests-pattern', '^sampletestsf?$',
16
>>> sys.argv = 'test --layer 122 -p'.split()
17
>>> from zope.testing import testrunner
18
>>> testrunner.run(defaults)
19
Running samplelayers.Layer122 tests:
20
Set up samplelayers.Layer1 in 0.000 seconds.
21
Set up samplelayers.Layer12 in 0.000 seconds.
22
Set up samplelayers.Layer122 in 0.000 seconds.
77
Ran 34 tests with 0 failures and 0 errors in 0.008 seconds.
78
Tearing down left over layers:
79
Tear down samplelayers.Layer122 in 0.000 seconds.
80
Tear down samplelayers.Layer12 in 0.000 seconds.
81
Tear down samplelayers.Layer1 in 0.000 seconds.
84
(Note that, in the examples above and below, we show "\r" followed by
85
new lines where carriage returns would appear in actual output.)
87
Using a single level of verbosity causes test descriptions to be
88
output, but only if they fit in the terminal width. The default
89
width, when the terminal width can't be determined, is 80:
91
>>> sys.argv = 'test --layer 122 -pv'.split()
92
>>> testrunner.run(defaults)
93
Running tests at level 1
94
Running samplelayers.Layer122 tests:
95
Set up samplelayers.Layer1 in 0.000 seconds.
96
Set up samplelayers.Layer12 in 0.000 seconds.
97
Set up samplelayers.Layer122 in 0.000 seconds.
99
1/34 (2.9%) test_x1 (sample1.sampletests.test122.TestA)\r
101
2/34 (5.9%) test_y0 (sample1.sampletests.test122.TestA)\r
103
3/34 (8.8%) test_z0 (sample1.sampletests.test122.TestA)\r
105
4/34 (11.8%) test_x0 (sample1.sampletests.test122.TestB)\r
107
5/34 (14.7%) test_y1 (sample1.sampletests.test122.TestB)\r
109
6/34 (17.6%) test_z0 (sample1.sampletests.test122.TestB)\r
111
7/34 (20.6%) test_1 (sample1.sampletests.test122.TestNotMuch)\r
113
8/34 (23.5%) test_2 (sample1.sampletests.test122.TestNotMuch)\r
115
9/34 (26.5%) test_3 (sample1.sampletests.test122.TestNotMuch)\r
117
10/34 (29.4%) test_x0 (sample1.sampletests.test122)\r
119
11/34 (32.4%) test_y0 (sample1.sampletests.test122)\r
121
12/34 (35.3%) test_z1 (sample1.sampletests.test122)\r
123
17/34 (50.0%) ... /testrunner-ex/sample1/sampletests/../../sampletestsl.txt\r
125
18/34 (52.9%) test_x1 (sampletests.test122.TestA)\r
127
19/34 (55.9%) test_y0 (sampletests.test122.TestA)\r
129
20/34 (58.8%) test_z0 (sampletests.test122.TestA)\r
131
21/34 (61.8%) test_x0 (sampletests.test122.TestB)\r
133
22/34 (64.7%) test_y1 (sampletests.test122.TestB)\r
135
23/34 (67.6%) test_z0 (sampletests.test122.TestB)\r
137
24/34 (70.6%) test_1 (sampletests.test122.TestNotMuch)\r
139
25/34 (73.5%) test_2 (sampletests.test122.TestNotMuch)\r
141
26/34 (76.5%) test_3 (sampletests.test122.TestNotMuch)\r
143
27/34 (79.4%) test_x0 (sampletests.test122)\r
145
28/34 (82.4%) test_y0 (sampletests.test122)\r
147
29/34 (85.3%) test_z1 (sampletests.test122)\r
149
34/34 (100.0%) ... pe/testing/testrunner-ex/sampletests/../sampletestsl.txt\r
152
Ran 34 tests with 0 failures and 0 errors in 0.008 seconds.
153
Tearing down left over layers:
154
Tear down samplelayers.Layer122 in 0.000 seconds.
155
Tear down samplelayers.Layer12 in 0.000 seconds.
156
Tear down samplelayers.Layer1 in 0.000 seconds.
159
The terminal width is determined using the curses module. To see
160
that, we'll provide a fake curses module:
162
>>> class FakeCurses:
163
... def setupterm(self):
165
... def tigetnum(self, ignored):
167
>>> old_curses = sys.modules.get('curses')
168
>>> sys.modules['curses'] = FakeCurses()
169
>>> testrunner.run(defaults)
170
Running tests at level 1
171
Running samplelayers.Layer122 tests:
172
Set up samplelayers.Layer1 in 0.000 seconds.
173
Set up samplelayers.Layer12 in 0.000 seconds.
174
Set up samplelayers.Layer122 in 0.000 seconds.
176
1/34 (2.9%) test_x1 (sample1.sampletests.test122.TestA)\r
178
2/34 (5.9%) test_y0 (sample1.sampletests.test122.TestA)\r
180
3/34 (8.8%) test_z0 (sample1.sampletests.test122.TestA)\r
182
4/34 (11.8%) test_x0 (...le1.sampletests.test122.TestB)\r
184
5/34 (14.7%) test_y1 (...le1.sampletests.test122.TestB)\r
186
6/34 (17.6%) test_z0 (...le1.sampletests.test122.TestB)\r
188
7/34 (20.6%) test_1 (...ampletests.test122.TestNotMuch)\r
190
8/34 (23.5%) test_2 (...ampletests.test122.TestNotMuch)\r
192
9/34 (26.5%) test_3 (...ampletests.test122.TestNotMuch)\r
194
10/34 (29.4%) test_x0 (sample1.sampletests.test122)\r
196
11/34 (32.4%) test_y0 (sample1.sampletests.test122)\r
198
12/34 (35.3%) test_z1 (sample1.sampletests.test122)\r
200
17/34 (50.0%) ... e1/sampletests/../../sampletestsl.txt\r
202
18/34 (52.9%) test_x1 (sampletests.test122.TestA)\r
204
19/34 (55.9%) test_y0 (sampletests.test122.TestA)\r
206
20/34 (58.8%) test_z0 (sampletests.test122.TestA)\r
208
21/34 (61.8%) test_x0 (sampletests.test122.TestB)\r
210
22/34 (64.7%) test_y1 (sampletests.test122.TestB)\r
212
23/34 (67.6%) test_z0 (sampletests.test122.TestB)\r
214
24/34 (70.6%) test_1 (sampletests.test122.TestNotMuch)\r
216
25/34 (73.5%) test_2 (sampletests.test122.TestNotMuch)\r
218
26/34 (76.5%) test_3 (sampletests.test122.TestNotMuch)\r
220
27/34 (79.4%) test_x0 (sampletests.test122)\r
222
28/34 (82.4%) test_y0 (sampletests.test122)\r
224
29/34 (85.3%) test_z1 (sampletests.test122)\r
226
34/34 (100.0%) ... r-ex/sampletests/../sampletestsl.txt\r
229
Ran 34 tests with 0 failures and 0 errors in 0.008 seconds.
230
Tearing down left over layers:
231
Tear down samplelayers.Layer122 in 0.000 seconds.
232
Tear down samplelayers.Layer12 in 0.000 seconds.
233
Tear down samplelayers.Layer1 in 0.000 seconds.
236
>>> sys.modules['curses'] = old_curses
238
If a second or third level of verbosity are added, we get additional
241
>>> sys.argv = 'test --layer 122 -pvv -t !txt'.split()
242
>>> testrunner.run(defaults)
243
Running tests at level 1
244
Running samplelayers.Layer122 tests:
245
Set up samplelayers.Layer1 in 0.000 seconds.
246
Set up samplelayers.Layer12 in 0.000 seconds.
247
Set up samplelayers.Layer122 in 0.000 seconds.
249
1/24 (4.2%) test_x1 (sample1.sampletests.test122.TestA)\r
251
2/24 (8.3%) test_y0 (sample1.sampletests.test122.TestA)\r
253
3/24 (12.5%) test_z0 (sample1.sampletests.test122.TestA)\r
255
4/24 (16.7%) test_x0 (sample1.sampletests.test122.TestB)\r
257
5/24 (20.8%) test_y1 (sample1.sampletests.test122.TestB)\r
259
6/24 (25.0%) test_z0 (sample1.sampletests.test122.TestB)\r
261
7/24 (29.2%) test_1 (sample1.sampletests.test122.TestNotMuch)\r
263
8/24 (33.3%) test_2 (sample1.sampletests.test122.TestNotMuch)\r
265
9/24 (37.5%) test_3 (sample1.sampletests.test122.TestNotMuch)\r
267
10/24 (41.7%) test_x0 (sample1.sampletests.test122)\r
269
11/24 (45.8%) test_y0 (sample1.sampletests.test122)\r
271
12/24 (50.0%) test_z1 (sample1.sampletests.test122)\r
273
13/24 (54.2%) test_x1 (sampletests.test122.TestA)\r
275
14/24 (58.3%) test_y0 (sampletests.test122.TestA)\r
277
15/24 (62.5%) test_z0 (sampletests.test122.TestA)\r
279
16/24 (66.7%) test_x0 (sampletests.test122.TestB)\r
281
17/24 (70.8%) test_y1 (sampletests.test122.TestB)\r
283
18/24 (75.0%) test_z0 (sampletests.test122.TestB)\r
285
19/24 (79.2%) test_1 (sampletests.test122.TestNotMuch)\r
287
20/24 (83.3%) test_2 (sampletests.test122.TestNotMuch)\r
289
21/24 (87.5%) test_3 (sampletests.test122.TestNotMuch)\r
291
22/24 (91.7%) test_x0 (sampletests.test122)\r
293
23/24 (95.8%) test_y0 (sampletests.test122)\r
295
24/24 (100.0%) test_z1 (sampletests.test122)\r
298
Ran 24 tests with 0 failures and 0 errors in 0.006 seconds.
299
Tearing down left over layers:
300
Tear down samplelayers.Layer122 in 0.000 seconds.
301
Tear down samplelayers.Layer12 in 0.000 seconds.
302
Tear down samplelayers.Layer1 in 0.000 seconds.
305
Note that, in this example, we used a test-selection pattern starting
306
with '!' to exclude tests containing the string "txt".
308
>>> sys.argv = 'test --layer 122 -pvvv -t!(txt|NotMuch)'.split()
309
>>> testrunner.run(defaults)
310
Running tests at level 1
311
Running samplelayers.Layer122 tests:
312
Set up samplelayers.Layer1 in 0.000 seconds.
313
Set up samplelayers.Layer12 in 0.000 seconds.
314
Set up samplelayers.Layer122 in 0.000 seconds.
316
1/18 (5.6%) test_x1 (sample1.sampletests.test122.TestA) (0.000 s)\r
318
2/18 (11.1%) test_y0 (sample1.sampletests.test122.TestA) (0.000 s)\r
320
3/18 (16.7%) test_z0 (sample1.sampletests.test122.TestA) (0.000 s)\r
322
4/18 (22.2%) test_x0 (sample1.sampletests.test122.TestB) (0.000 s)\r
324
5/18 (27.8%) test_y1 (sample1.sampletests.test122.TestB) (0.000 s)\r
326
6/18 (33.3%) test_z0 (sample1.sampletests.test122.TestB) (0.000 s)\r
328
7/18 (38.9%) test_x0 (sample1.sampletests.test122) (0.001 s)\r
330
8/18 (44.4%) test_y0 (sample1.sampletests.test122) (0.001 s)\r
332
9/18 (50.0%) test_z1 (sample1.sampletests.test122) (0.001 s)\r
334
10/18 (55.6%) test_x1 (sampletests.test122.TestA) (0.000 s)\r
336
11/18 (61.1%) test_y0 (sampletests.test122.TestA) (0.000 s)\r
338
12/18 (66.7%) test_z0 (sampletests.test122.TestA) (0.000 s)\r
340
13/18 (72.2%) test_x0 (sampletests.test122.TestB) (0.000 s)\r
342
14/18 (77.8%) test_y1 (sampletests.test122.TestB) (0.000 s)\r
344
15/18 (83.3%) test_z0 (sampletests.test122.TestB) (0.000 s)\r
346
16/18 (88.9%) test_x0 (sampletests.test122) (0.001 s)\r
348
17/18 (94.4%) test_y0 (sampletests.test122) (0.001 s)\r
350
18/18 (100.0%) test_z1 (sampletests.test122) (0.001 s)\r
353
Ran 18 tests with 0 failures and 0 errors in 0.006 seconds.
354
Tearing down left over layers:
355
Tear down samplelayers.Layer122 in 0.000 seconds.
356
Tear down samplelayers.Layer12 in 0.000 seconds.
357
Tear down samplelayers.Layer1 in 0.000 seconds.
360
In this example, we also excluded tests with "NotMuch" in their names.
362
Unfortunately, the time data above doesn't buy us much because, in
363
practice, the line is cleared before there is time to see the
367
Autodetecting progress
368
----------------------
370
The --auto-progress option will determine if stdout is a terminal, and only enable
371
progress output if so.
373
Let's pretend we have a terminal
375
>>> class Terminal(object):
376
... def __init__(self, stream):
377
... self._stream = stream
378
... def __getattr__(self, attr):
379
... return getattr(self._stream, attr)
380
... def isatty(self):
382
>>> real_stdout = sys.stdout
383
>>> sys.stdout = Terminal(sys.stdout)
385
>>> sys.argv = 'test -u -t test_one.TestNotMuch --auto-progress'.split()
386
>>> testrunner.run(defaults)
402
Ran 6 tests with 0 failures and 0 errors in 0.000 seconds.
405
Let's stop pretending
407
>>> sys.stdout = real_stdout
409
>>> sys.argv = 'test -u -t test_one.TestNotMuch --auto-progress'.split()
410
>>> testrunner.run(defaults)
412
Ran 6 tests with 0 failures and 0 errors in 0.000 seconds.
416
Disabling progress indication
417
-----------------------------
419
If -p or --progress have been previously provided on the command line (perhaps by a
420
wrapper script) but you do not desire progress indication, you can switch it off with
423
>>> sys.argv = 'test -u -t test_one.TestNotMuch -p --no-progress'.split()
424
>>> testrunner.run(defaults)
426
Ran 6 tests with 0 failures and 0 errors in 0.000 seconds.