[conduit: 46/138] Allow running tests in a random order
- From: John Carr <johncarr src gnome org>
- To: svn-commits-list gnome org
- Subject: [conduit: 46/138] Allow running tests in a random order
- Date: Thu, 21 May 2009 03:30:48 -0400 (EDT)
commit 8a1447e51c4a1dbb6d16cbfc6e5d13090015af49
Author: John Carr <john carr unrouted co uk>
Date: Wed Apr 29 12:59:38 2009 -0700
Allow running tests in a random order
---
test/soup/soup | 41 +++++++++++++++++++++++------------------
1 files changed, 23 insertions(+), 18 deletions(-)
diff --git a/test/soup/soup b/test/soup/soup
index 6fbf057..c0a96db 100755
--- a/test/soup/soup
+++ b/test/soup/soup
@@ -13,21 +13,14 @@ import unittest
def run_tests(tests):
runner = unittest.TextTestRunner(verbosity=2)
- result = runner.run(suite)
- sys.exit(not result.wasSuccessfull())
+ result = runner.run(unittest.TestSuite(tests))
+ sys.exit(not result.wasSuccessful())
def list_tests(tests):
- def flatten(tests):
- if isinstance(tests, unittest.TestSuite):
- res = []
- for test in tests:
- res.extend(flatten(test))
- return res
- else:
- return [tests]
- tests = flatten(tests)
for test in tests:
print test.name(), test.testMethodName
+ sys.exit(0)
+
if __name__ == "__main__":
import optparse
@@ -49,21 +42,33 @@ if __name__ == "__main__":
help="Run the tests")
# Set parse defaults
- parser.set_defaults(mode="execute")
+ parser.set_defaults(mode="execute", randomize=False)
# And parse..
opts, args = parser.parse_args()
# Figure out which tests to run
loader = unittest.TestLoader()
- suite = loader.loadTestsFromModule(__import__('__main__'))
+ tests = loader.loadTestsFromModule(__import__('__main__'))
+
+ # Temporary - flatten tests
+ def flatten(tests):
+ if isinstance(tests, unittest.TestSuite):
+ res = []
+ for test in tests:
+ res.extend(flatten(test))
+ return res
+ else:
+ return [tests]
+ tests = flatten(tests)
+
+ if opts.randomize:
+ import random
+ random.shuffle(tests)
# And run.
if opts.mode == "execute":
- run_tests(suite)
+ run_tests(tests)
elif opts.mode == "list":
- list_tests(suite)
- else:
- print "I don't know what to do :("
- sys.exit(1)
+ list_tests(tests)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]