[Zope-dev] coverage.py,
profile and hotshot support in Zope's testrunner
Stefane Fermigier
sf at nuxeo.com
Sun Aug 21 04:20:28 EDT 2005
I have added support for coverage analysis using coverage.py from Gareth Rees
and Ned Batchelder, as well as support for profiling using either the profile or
hotshot modules from the Python standard library, to Zope 2's test runner test.py.
Justification:
- coverage.py will let you interactively focus on the modules you want to check
for coverage.
- profile is slow to collect data but quick for analysis.
- hotshot is fast when collecting but very slow for analysis. On the other hand,
one can feed the great KCacheGrind tool with hotshot data after some
transformation and this is the best way I have found so far for interactively
exploring profile data.
Since I'm not a regular Zope commiter, I'd like to ask for comments and
permission first before commiting.
The test.py file is here:
http://blogs.nuxeo.com/sections/blogs/fermigier/2005_08_21_coverage-py-profile
BTW: the patch is absolutely trivial (see attached file).
S.
--
Stéfane Fermigier, Tel: +33 (0)6 63 04 12 77 (mobile).
Nuxeo Collaborative Portal Server: http://www.nuxeo.com/cps
Gestion de contenu web / portail collaboratif / groupware / open source!
-------------- next part --------------
1c1
< #!/home/fermigier/bin/python
---
> #!/usr/bin/env python2.3
124,143d123
< --coverage
< Use the coverage.py module from Gareth Rees
< (http://www.nedbatchelder.com/code/modules/coverage.html) to collect data
< for code coverage. This will output trace data in a file called
< '.coverage'. You will need to call coverage.py after the test run to
< analyse the data (-r for a line count report, -a for annotated file).
<
< --profile
< Use the profile module from the standard library to collect profiling data.
< This will output data in a file called '.profile'. You will need to use the
< pstats module from the standard library after the test run to analyse the
< data.
<
< --hotshot
< Use the hotshot module from the standard library to collect profiling data.
< This will output data in a file called '.hotshot'. You will need to use the
< hotshot.pstats module from the standard library after the test run to
< analyse the data. You may also use the hotshot2cg script from the
< KCacheGrind sources to create data suitable for analysis by KCacheGrind.
<
772,774d751
< COVERAGE = False
< PROFILE = False
< HOTSHOT = False
797,798c774
< "config-file=", "import-testing",
< "coverage", "profile", "hotshot"])
---
> "config-file=", "import-testing"])
850,855d825
< elif k == "--coverage":
< COVERAGE = True
< elif k == "--profile":
< PROFILE = True
< elif k == "--hotshot":
< HOTSHOT = True
936,958d905
<
< elif COVERAGE:
< try:
< from coverage import the_coverage
< except:
< print "You need to install coverage.py from "
< print "http://www.nedbatchelder.com/code/modules/coverage.html"
< sys.exit()
< the_coverage.start()
< main(module_filter, test_filter, libdir)
<
< elif PROFILE:
< import profile
< profile.runctx("main(module_filter, test_filter, libdir)",
< globals=globals(), locals=vars(),
< filename=".profile")
<
< elif HOTSHOT:
< import hotshot
< profile = hotshot.Profile(".hotshot")
< profile.runctx("main(module_filter, test_filter, libdir)",
< globals=globals(), locals=vars())
<
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sf.vcf
Type: text/x-vcard
Size: 307 bytes
Desc: not available
Url : http://mail.zope.org/pipermail/zope-dev/attachments/20050821/c8020eea/sf.vcf
More information about the Zope-Dev
mailing list