Rev 3116: Cherry-pick Robert's load_test() test feature as it is exactly what we in file:///v/home/vila/src/bzr/bugs/175524/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Tue Dec 18 21:31:47 GMT 2007
At file:///v/home/vila/src/bzr/bugs/175524/
------------------------------------------------------------
revno: 3116
revision-id:v.ladeuil+lp at free.fr-20071218213144-h276togzls9mi4g4
parent: v.ladeuil+lp at free.fr-20071218135304-rqiekrykivoq8qdm
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 175524
timestamp: Tue 2007-12-18 22:31:44 +0100
message:
Cherry-pick Robert's load_test() test feature as it is exactly what we
need.
modified:
bzrlib/tests/TestUtil.py TestUtil.py-20050824080200-5f70140a2d938694
-------------- next part --------------
=== modified file 'bzrlib/tests/TestUtil.py'
--- a/bzrlib/tests/TestUtil.py 2007-04-23 03:41:48 +0000
+++ b/bzrlib/tests/TestUtil.py 2007-12-18 21:31:44 +0000
@@ -86,10 +86,41 @@
"""
result = self.suiteClass()
for name in names:
- _load_module_by_name(name)
- result.addTests(self.loadTestsFromName(name))
+ module = _load_module_by_name(name)
+ result.addTests(self.loadTestsFromModule(module))
return result
+ def loadTestsFromModule(self, module):
+ """Load tests from a module object.
+
+ This extension of the python test loader looks for an attribute
+ load_tests in the module object, and if not found falls back to the
+ regular python loadTestsFromModule.
+
+ If a load_tests attribute is found, it is called and the result is
+ returned.
+
+ load_tests should be defined like so:
+ >>> def load_tests(standard_tests, module, loader):
+ >>> pass
+
+ standard_tests is the tests found by the stock TestLoader in the
+ module, module and loader are the module and loader instances.
+
+ For instance, to run every test twice, you might do:
+ >>> def load_tests(standard_tests, module, loader):
+ >>> result = loader.suiteClass()
+ >>> for test in iter_suite_tests(standard_tests):
+ >>> result.addTests([test, test])
+ >>> return result
+ """
+ basic_tests = super(TestLoader, self).loadTestsFromModule(module)
+ load_tests = getattr(module, "load_tests", None)
+ if load_tests is not None:
+ return load_tests(basic_tests, module, self)
+ else:
+ return basic_tests
+
def _load_module_by_name(mod_name):
parts = mod_name.split('.')
More information about the bazaar-commits
mailing list