416
402
self.pb.update('[test 0/%d] starting...' % (self.num_tests))
418
404
def _progress_prefix_text(self):
419
a = '[%d' % self.count
405
# the longer this text, the less space we have to show the test
407
a = '[%d' % self.count # total that have been run
408
# tests skipped as known not to be relevant are not important enough
410
## if self.skip_count:
411
## a += ', %d skip' % self.skip_count
412
## if self.known_failure_count:
413
## a += '+%dX' % self.known_failure_count
420
414
if self.num_tests is not None:
421
415
a +='/%d' % self.num_tests
422
a += ' in %ds' % (time.time() - self._overall_start_time)
417
runtime = time.time() - self._overall_start_time
419
a += '%dm%ds' % (runtime / 60, runtime % 60)
423
422
if self.error_count:
424
a += ', %d errors' % self.error_count
423
a += ', %d err' % self.error_count
425
424
if self.failure_count:
426
a += ', %d failed' % self.failure_count
427
if self.known_failure_count:
428
a += ', %d known failures' % self.known_failure_count
430
a += ', %d skipped' % self.skip_count
425
a += ', %d fail' % self.failure_count
431
426
if self.unsupported:
432
a += ', %d missing features' % len(self.unsupported)
427
a += ', %d missing' % len(self.unsupported)
2573
2582
return test_list
2585
def suite_matches_id_list(test_suite, id_list):
2586
"""Warns about tests not appearing or appearing more than once.
2588
:param test_suite: A TestSuite object.
2589
:param test_id_list: The list of test ids that should be found in
2592
:return: (absents, duplicates) absents is a list containing the test found
2593
in id_list but not in test_suite, duplicates is a list containing the
2594
test found multiple times in test_suite.
2596
When using a prefined test id list, it may occurs that some tests do not
2597
exist anymore or that some tests use the same id. This function warns the
2598
tester about potential problems in his workflow (test lists are volatile)
2599
or in the test suite itself (using the same id for several tests does not
2600
help to localize defects).
2602
# Build a dict counting id occurrences
2604
for test in iter_suite_tests(test_suite):
2606
tests[id] = tests.get(id, 0) + 1
2611
occurs = tests.get(id, 0)
2613
not_found.append(id)
2615
duplicates.append(id)
2617
return not_found, duplicates
2576
2620
class TestIdList(object):
2577
2621
"""Test id list to filter a test suite.
2758
2805
'bzrlib.tests.test_transport_implementations',
2759
2806
'bzrlib.tests.test_read_bundle',
2761
suite = TestUtil.TestSuite()
2762
2808
loader = TestUtil.TestLoader()
2764
if keep_only is not None:
2810
if keep_only is None:
2811
loader = TestUtil.TestLoader()
2765
2813
id_filter = TestIdList(keep_only)
2814
loader = TestUtil.FilteredByModuleTestLoader(id_filter.refers_to)
2815
suite = loader.suiteClass()
2767
2817
# modules building their suite with loadTestsFromModuleNames
2768
if keep_only is None:
2769
suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
2771
for mod in [m for m in testmod_names
2772
if id_filter.is_module_name_used(m)]:
2773
mod_suite = loader.loadTestsFromModuleNames([mod])
2774
mod_suite = filter_suite_by_id_list(mod_suite, id_filter)
2775
suite.addTest(mod_suite)
2818
suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
2777
2820
# modules adapted for transport implementations
2778
2821
from bzrlib.tests.test_transport_implementations import TransportTestProviderAdapter
2779
2822
adapter = TransportTestProviderAdapter()
2780
if keep_only is None:
2781
adapt_modules(test_transport_implementations, adapter, loader, suite)
2783
for mod in [m for m in test_transport_implementations
2784
if id_filter.is_module_name_used(m)]:
2785
mod_suite = TestUtil.TestSuite()
2786
adapt_modules([mod], adapter, loader, mod_suite)
2787
mod_suite = filter_suite_by_id_list(mod_suite, id_filter)
2788
suite.addTest(mod_suite)
2823
adapt_modules(test_transport_implementations, adapter, loader, suite)
2790
2825
# modules defining their own test_suite()
2791
2826
for package in [p for p in packages_to_test()
2792
2827
if (keep_only is None
2793
or id_filter.is_module_name_used(p.__name__))]:
2828
or id_filter.refers_to(p.__name__))]:
2794
2829
pack_suite = package.test_suite()
2795
if keep_only is not None:
2796
pack_suite = filter_suite_by_id_list(pack_suite, id_filter)
2797
2830
suite.addTest(pack_suite)
2799
# XXX: MODULES_TO_TEST should be obsoleted ?
2800
for mod in [m for m in MODULES_TO_TEST
2801
if keep_only is None or id_filter.is_module_name_used(m)]:
2802
mod_suite = loader.loadTestsFromModule(mod)
2803
if keep_only is not None:
2804
mod_suite = filter_suite_by_id_list(mod_suite, id_filter)
2805
suite.addTest(mod_suite)
2832
modules_to_doctest = [
2837
'bzrlib.iterablefile',
2844
'bzrlib.version_info_formats.format_custom',
2807
for mod in MODULES_TO_DOCTEST:
2847
for mod in modules_to_doctest:
2848
if not (keep_only is None or id_filter.refers_to(mod)):
2849
# No tests to keep here, move along
2809
2852
doc_suite = doctest.DocTestSuite(mod)
2810
2853
except ValueError, e:
2811
2854
print '**failed to get doctest for: %s\n%s' % (mod, e)
2813
if keep_only is not None:
2814
# DocTests may use ids which doesn't contain the module name
2815
doc_suite = filter_suite_by_id_list(doc_suite, id_filter)
2816
2856
suite.addTest(doc_suite)
2818
2858
default_encoding = sys.getdefaultencoding()
2819
2859
for name, plugin in bzrlib.plugin.plugins().items():
2820
2860
if keep_only is not None:
2821
if not id_filter.is_module_name_used(plugin.module.__name__):
2861
if not id_filter.refers_to(plugin.module.__name__):
2823
2863
plugin_suite = plugin.test_suite()
2824
2864
# We used to catch ImportError here and turn it into just a warning,
2825
2865
# but really if you don't have --no-plugins this should be a failure.
2826
2866
# mbp 20080213 - see http://bugs.launchpad.net/bugs/189771
2867
if plugin_suite is None:
2868
plugin_suite = plugin.load_plugin_tests(loader)
2827
2869
if plugin_suite is not None:
2828
if keep_only is not None:
2829
plugin_suite = filter_suite_by_id_list(plugin_suite,
2831
2870
suite.addTest(plugin_suite)
2832
2871
if default_encoding != sys.getdefaultencoding():
2833
2872
bzrlib.trace.warning(
2835
2874
sys.getdefaultencoding())
2837
2876
sys.setdefaultencoding(default_encoding)
2878
if keep_only is not None:
2879
# Now that the referred modules have loaded their tests, keep only the
2881
suite = filter_suite_by_id_list(suite, id_filter)
2882
# Do some sanity checks on the id_list filtering
2883
not_found, duplicates = suite_matches_id_list(suite, keep_only)
2884
for id in not_found:
2885
bzrlib.trace.warning('"%s" not found in the test suite', id)
2886
for id in duplicates:
2887
bzrlib.trace.warning('"%s" is used as an id by several tests', id)
2841
def multiply_tests_from_modules(module_name_list, scenario_iter):
2892
def multiply_tests_from_modules(module_name_list, scenario_iter, loader=None):
2842
2893
"""Adapt all tests in some given modules to given scenarios.
2844
2895
This is the recommended public interface for test parameterization.