4
The testrunner includes the ability to profile the test execution with hotshot
5
via the --profile option.
7
>>> import os.path, sys
8
>>> directory_with_tests = os.path.join(this_directory, 'testrunner-ex')
9
>>> sys.path.append(directory_with_tests)
12
... '--path', directory_with_tests,
13
... '--tests-pattern', '^sampletestsf?$',
16
>>> sys.argv = [testrunner_script, '--profile=hotshot']
18
When the tests are run, we get profiling output.
20
>>> from zope.testing import testrunner
21
>>> testrunner.run_internal(defaults)
22
Running samplelayers.Layer1 tests:
24
Running samplelayers.Layer11 tests:
26
Running zope.testing.testrunner.layer.UnitTests tests:
28
ncalls tottime percall cumtime percall filename:lineno(function)
30
Total: ... tests, 0 failures, 0 errors in ... seconds.
33
Profiling also works across layers.
35
>>> sys.argv = [testrunner_script, '-ssample2', '--profile=hotshot',
36
... '--tests-pattern', 'sampletests_ntd']
37
>>> testrunner.run_internal(defaults)
39
Tear down ... not supported...
40
ncalls tottime percall cumtime percall filename:lineno(function)...
42
The testrunner creates temnporary files containing hotshot profiler
46
>>> files = list(glob.glob('tests_profile.*.prof'))
49
['tests_profile.cZj2jt.prof', 'tests_profile.yHD-so.prof']
51
It deletes these when rerun. We'll delete these ourselves: