417
402
self.pb.update('[test 0/%d] starting...' % (self.num_tests))
419
404
def _progress_prefix_text(self):
420
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
421
414
if self.num_tests is not None:
422
415
a +='/%d' % self.num_tests
423
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)
424
422
if self.error_count:
425
a += ', %d errors' % self.error_count
423
a += ', %d err' % self.error_count
426
424
if self.failure_count:
427
a += ', %d failed' % self.failure_count
428
if self.known_failure_count:
429
a += ', %d known failures' % self.known_failure_count
431
a += ', %d skipped' % self.skip_count
425
a += ', %d fail' % self.failure_count
432
426
if self.unsupported:
433
a += ', %d missing features' % len(self.unsupported)
427
a += ', %d missing' % len(self.unsupported)
2575
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
2578
2620
class TestIdList(object):
2579
2621
"""Test id list to filter a test suite.
2762
2805
'bzrlib.tests.test_transport_implementations',
2763
2806
'bzrlib.tests.test_read_bundle',
2765
suite = TestUtil.TestSuite()
2766
2808
loader = TestUtil.TestLoader()
2768
if keep_only is not None:
2810
if keep_only is None:
2811
loader = TestUtil.TestLoader()
2769
2813
id_filter = TestIdList(keep_only)
2814
loader = TestUtil.FilteredByModuleTestLoader(id_filter.refers_to)
2815
suite = loader.suiteClass()
2771
2817
# modules building their suite with loadTestsFromModuleNames
2772
if keep_only is None:
2773
suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
2775
for mod in [m for m in testmod_names
2776
if id_filter.is_module_name_used(m)]:
2777
mod_suite = loader.loadTestsFromModuleNames([mod])
2778
mod_suite = filter_suite_by_id_list(mod_suite, id_filter)
2779
suite.addTest(mod_suite)
2818
suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
2781
2820
# modules adapted for transport implementations
2782
2821
from bzrlib.tests.test_transport_implementations import TransportTestProviderAdapter
2783
2822
adapter = TransportTestProviderAdapter()
2784
if keep_only is None:
2785
adapt_modules(test_transport_implementations, adapter, loader, suite)
2787
for mod in [m for m in test_transport_implementations
2788
if id_filter.is_module_name_used(m)]:
2789
mod_suite = TestUtil.TestSuite()
2790
adapt_modules([mod], adapter, loader, mod_suite)
2791
mod_suite = filter_suite_by_id_list(mod_suite, id_filter)
2792
suite.addTest(mod_suite)
2823
adapt_modules(test_transport_implementations, adapter, loader, suite)
2794
2825
# modules defining their own test_suite()
2795
2826
for package in [p for p in packages_to_test()
2796
2827
if (keep_only is None
2797
or id_filter.is_module_name_used(p.__name__))]:
2828
or id_filter.refers_to(p.__name__))]:
2798
2829
pack_suite = package.test_suite()
2799
if keep_only is not None:
2800
pack_suite = filter_suite_by_id_list(pack_suite, id_filter)
2801
2830
suite.addTest(pack_suite)
2803
# XXX: MODULES_TO_TEST should be obsoleted ?
2804
for mod in [m for m in MODULES_TO_TEST
2805
if keep_only is None or id_filter.is_module_name_used(m)]:
2806
mod_suite = loader.loadTestsFromModule(mod)
2807
if keep_only is not None:
2808
mod_suite = filter_suite_by_id_list(mod_suite, id_filter)
2809
suite.addTest(mod_suite)
2832
modules_to_doctest = [
2837
'bzrlib.iterablefile',
2844
'bzrlib.version_info_formats.format_custom',
2811
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
2813
2852
doc_suite = doctest.DocTestSuite(mod)
2814
2853
except ValueError, e:
2815
2854
print '**failed to get doctest for: %s\n%s' % (mod, e)
2817
if keep_only is not None:
2818
# DocTests may use ids which doesn't contain the module name
2819
doc_suite = filter_suite_by_id_list(doc_suite, id_filter)
2820
2856
suite.addTest(doc_suite)
2822
2858
default_encoding = sys.getdefaultencoding()
2823
2859
for name, plugin in bzrlib.plugin.plugins().items():
2824
2860
if keep_only is not None:
2825
if not id_filter.is_module_name_used(plugin.module.__name__):
2861
if not id_filter.refers_to(plugin.module.__name__):
2827
2863
plugin_suite = plugin.test_suite()
2828
2864
# We used to catch ImportError here and turn it into just a warning,
2829
2865
# but really if you don't have --no-plugins this should be a failure.
2830
2866
# mbp 20080213 - see http://bugs.launchpad.net/bugs/189771
2867
if plugin_suite is None:
2868
plugin_suite = plugin.load_plugin_tests(loader)
2831
2869
if plugin_suite is not None:
2832
if keep_only is not None:
2833
plugin_suite = filter_suite_by_id_list(plugin_suite,
2835
2870
suite.addTest(plugin_suite)
2836
2871
if default_encoding != sys.getdefaultencoding():
2837
2872
bzrlib.trace.warning(
2839
2874
sys.getdefaultencoding())
2841
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)
2845
def multiply_tests_from_modules(module_name_list, scenario_iter):
2892
def multiply_tests_from_modules(module_name_list, scenario_iter, loader=None):
2846
2893
"""Adapt all tests in some given modules to given scenarios.
2848
2895
This is the recommended public interface for test parameterization.