summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorludal <ludal@logilab.fr>2009-02-17 23:36:14 +0100
committerludal <ludal@logilab.fr>2009-02-17 23:36:14 +0100
commit91797aed7782a088a7f948e7ee3b5c5374771fd9 (patch)
tree156a682c15a0a936071cc1bb341a643b3de56cd4
parent473c64dfbb9c1d65f5517e544ccd017780da477f (diff)
downloadlogilab-common-91797aed7782a088a7f948e7ee3b5c5374771fd9.tar.gz
add profile option to testlib. this uses cProfile and complements hotshot used by pytest
-rw-r--r--testlib.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/testlib.py b/testlib.py
index 76efcc5..e7c7b60 100644
--- a/testlib.py
+++ b/testlib.py
@@ -761,6 +761,9 @@ Options:
-m, --match Run only test whose tag match this pattern
+ -P, --profile FILE: Run the tests using cProfile and saving results
+ in FILE
+
Examples:
%(progName)s - run default set of tests
%(progName)s MyTestSuite - run suite 'MyTestSuite'
@@ -787,12 +790,13 @@ Examples:
self.test_pattern = None
self.tags_pattern = None
self.colorize = False
+ self.profile_name = None
import getopt
try:
- options, args = getopt.getopt(argv[1:], 'hHvixrqcp:s:m:',
+ options, args = getopt.getopt(argv[1:], 'hHvixrqcp:s:m:P:',
['help', 'verbose', 'quiet', 'pdb',
'exitfirst', 'restart', 'capture', 'printonly=',
- 'skip=', 'color', 'match='])
+ 'skip=', 'color', 'match=', 'profile='])
for opt, value in options:
if opt in ('-h', '-H', '--help'):
self.usageExit()
@@ -819,6 +823,8 @@ Examples:
if opt in ('-m', '--match'):
#self.tags_pattern = value
self.options["tag_pattern"] = value
+ if opt in ('-P', '--profile'):
+ self.profile_name = value
self.testLoader.skipped_patterns = self.skipped_patterns
if self.printonly is not None:
self.capture += 1
@@ -841,6 +847,13 @@ Examples:
def runTests(self):
+ if self.profile_name:
+ import cProfile
+ cProfile.runctx('self._runTests()', globals(), locals(), self.profile_name )
+ else:
+ return self._runTests()
+
+ def _runTests(self):
if hasattr(self.module, 'setup_module'):
try:
self.module.setup_module(self.options)