summaryrefslogtreecommitdiff
path: root/pytest.py
diff options
context:
space:
mode:
authorSylvain <syt@logilab.fr>2007-11-26 16:55:41 +0100
committerSylvain <syt@logilab.fr>2007-11-26 16:55:41 +0100
commitbb675d28e04a76ccc8c2e0cd49047074f2d807ab (patch)
tree9c0da2a1581f586f23a64ec4b10c991f81a4e0ad /pytest.py
parent7f10bb99c2c7d0cf4fd93bc03a2b9de7486722ee (diff)
downloadlogilab-common-bb675d28e04a76ccc8c2e0cd49047074f2d807ab.tar.gz
profile option for pytest
Diffstat (limited to 'pytest.py')
-rw-r--r--pytest.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/pytest.py b/pytest.py
index b0fca8d..10b19f7 100644
--- a/pytest.py
+++ b/pytest.py
@@ -468,6 +468,8 @@ def parseargs():
"to skip several patterns, use commas")
parser.add_option('-q', '--quiet', callback=rebuild_cmdline,
action="callback", help="Minimal output")
+ parser.add_option('-P', '--profile', default=None, dest='profile',
+ help="Profile execution and store data in the given file")
try:
from logilab.devtools.lib.coverage import Coverage
@@ -523,14 +525,22 @@ def run():
tester = DjangoTester(cvg)
else:
tester = PyTester(cvg)
+ if explicitfile:
+ cmd, args = tester.testfile, (explicitfile,)
+ elif options.testdir:
+ cmd, args = tester.testonedir, (options.testdir, options.exitfirst)
+ else:
+ cmd, args = tester.testall, (options.exitfirst,)
try:
try:
- if explicitfile:
- tester.testfile(explicitfile)
- elif options.testdir:
- tester.testonedir(options.testdir, options.exitfirst)
+ if options.profile:
+ import hotshot
+ prof = hotshot.Profile(options.profile)
+ prof.runcall(cmd, *args)
+ prof.close()
+ print 'profile data saved in', options.profile
else:
- tester.testall(options.exitfirst)
+ cmd(*args)
except SystemExit:
raise
except: