~landscape/zope3/ztk-1.1.3

« back to all changes in this revision

Viewing changes to src/zope/testing/testrunner/testrunner-profiling.txt

  • 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
Profiling
 
2
=========
 
3
 
 
4
The testrunner includes the ability to profile the test execution with hotshot
 
5
via the --profile option.
 
6
 
 
7
    >>> import os.path, sys
 
8
    >>> directory_with_tests = os.path.join(this_directory, 'testrunner-ex')
 
9
    >>> sys.path.append(directory_with_tests)
 
10
 
 
11
    >>> defaults = [
 
12
    ...     '--path', directory_with_tests,
 
13
    ...     '--tests-pattern', '^sampletestsf?$',
 
14
    ...     ]
 
15
 
 
16
    >>> sys.argv = [testrunner_script, '--profile=hotshot']
 
17
 
 
18
When the tests are run, we get profiling output.
 
19
 
 
20
    >>> from zope.testing import testrunner
 
21
    >>> testrunner.run_internal(defaults)
 
22
    Running samplelayers.Layer1 tests:
 
23
    ...
 
24
    Running samplelayers.Layer11 tests:
 
25
    ...
 
26
    Running zope.testing.testrunner.layer.UnitTests tests:
 
27
    ...
 
28
       ncalls  tottime  percall  cumtime  percall filename:lineno(function)
 
29
    ...
 
30
    Total: ... tests, 0 failures, 0 errors in ... seconds.
 
31
    False
 
32
 
 
33
Profiling also works across layers.
 
34
 
 
35
    >>> sys.argv = [testrunner_script, '-ssample2', '--profile=hotshot',
 
36
    ...             '--tests-pattern', 'sampletests_ntd']
 
37
    >>> testrunner.run_internal(defaults)
 
38
    Running...
 
39
      Tear down ... not supported...
 
40
       ncalls  tottime  percall  cumtime  percall filename:lineno(function)...
 
41
 
 
42
The testrunner creates temnporary files containing hotshot profiler
 
43
data:
 
44
 
 
45
    >>> import glob
 
46
    >>> files = list(glob.glob('tests_profile.*.prof'))
 
47
    >>> files.sort()
 
48
    >>> files
 
49
    ['tests_profile.cZj2jt.prof', 'tests_profile.yHD-so.prof']
 
50
 
 
51
It deletes these when rerun.  We'll delete these ourselves:
 
52
 
 
53
    >>> import os
 
54
    >>> for f in files:
 
55
    ...     os.unlink(f)