226
226
self._recordTestStartTime()
228
228
def startTests(self):
230
'testing: %s\n' % (osutils.realpath(sys.argv[0]),))
232
' %s (%s python%s)\n' % (
230
if getattr(sys, 'frozen', None) is None:
231
bzr_path = osutils.realpath(sys.argv[0])
233
bzr_path = sys.executable
235
'testing: %s\n' % (bzr_path,))
238
bzrlib.__path__[0],))
240
' bzr-%s python-%s %s\n' % (
234
241
bzrlib.version_string,
235
242
bzrlib._format_version_tuple(sys.version_info),
243
platform.platform(aliased=1),
237
245
self.stream.write('\n')
571
579
bench_history=None,
582
result_decorators=None,
584
"""Create a TextTestRunner.
586
:param result_decorators: An optional list of decorators to apply
587
to the result object being used by the runner. Decorators are
588
applied left to right - the first element in the list is the
575
591
self.stream = unittest._WritelnDecorator(stream)
576
592
self.descriptions = descriptions
577
593
self.verbosity = verbosity
578
594
self._bench_history = bench_history
579
595
self.list_only = list_only
580
596
self._strict = strict
597
self._result_decorators = result_decorators or []
582
599
def run(self, test):
583
600
"Run the given test case or test suite."
592
609
bench_history=self._bench_history,
593
610
strict=self._strict,
613
for decorator in self._result_decorators:
614
run_result = decorator(run_result)
595
615
result.stop_early = self.stop_on_failure
596
616
result.report_starting()
597
617
if self.list_only:
608
628
except ImportError:
611
631
if isinstance(test, testtools.ConcurrentTestSuite):
612
632
# We need to catch bzr specific behaviors
613
test.run(BZRTransformingResult(result))
633
test.run(BZRTransformingResult(run_result))
616
636
run = result.testsRun
617
637
actionTaken = "Ran"
618
638
stopTime = time.time()
843
862
self._preserved_debug_flags = set(debug.debug_flags)
844
863
if 'allow_debug' not in selftest_debug_flags:
845
864
debug.debug_flags.clear()
865
if 'disable_lock_checks' not in selftest_debug_flags:
866
debug.debug_flags.add('strict_locks')
846
867
self.addCleanup(self._restore_debug_flags)
848
869
def _clear_hooks(self):
871
892
def _check_locks(self):
872
893
"""Check that all lock take/release actions have been paired."""
873
# once we have fixed all the current lock problems, we can change the
874
# following code to always check for mismatched locks, but only do
875
# traceback showing with -Dlock (self._lock_check_thorough is True).
876
# For now, because the test suite will fail, we only assert that lock
877
# matching has occured with -Dlock.
894
# We always check for mismatched locks. If a mismatch is found, we
895
# fail unless -Edisable_lock_checks is supplied to selftest, in which
896
# case we just print a warning.
879
898
acquired_locks = [lock for action, lock in self._lock_actions
880
899
if action == 'acquired']
899
918
def _track_locks(self):
900
919
"""Track lock activity during tests."""
901
920
self._lock_actions = []
902
self._lock_check_thorough = 'lock' not in debug.debug_flags
921
if 'disable_lock_checks' in selftest_debug_flags:
922
self._lock_check_thorough = False
924
self._lock_check_thorough = True
903
926
self.addCleanup(self._check_locks)
904
927
_mod_lock.Lock.hooks.install_named_hook('lock_acquired',
905
928
self._lock_acquired, None)
1321
1344
"""Make the logfile not be deleted when _finishLogFile is called."""
1322
1345
self._keep_log_file = True
1347
def thisFailsStrictLockCheck(self):
1348
"""It is known that this test would fail with -Dstrict_locks.
1350
By default, all tests are run with strict lock checking unless
1351
-Edisable_lock_checks is supplied. However there are some tests which
1352
we know fail strict locks at this point that have not been fixed.
1353
They should call this function to disable the strict checking.
1355
This should be used sparingly, it is much better to fix the locking
1356
issues rather than papering over the problem by calling this function.
1358
debug.debug_flags.discard('strict_locks')
1324
1360
def addCleanup(self, callable, *args, **kwargs):
1325
1361
"""Arrange to run a callable when this case is torn down.
1938
1974
sio.encoding = output_encoding
1977
def disable_verb(self, verb):
1978
"""Disable a smart server verb for one test."""
1979
from bzrlib.smart import request
1980
request_handlers = request.request_handlers
1981
orig_method = request_handlers.get(verb)
1982
request_handlers.remove(verb)
1984
request_handlers.register(verb, orig_method)
1985
self.addCleanup(restoreVerb)
1942
1988
class CapturedCall(object):
1943
1989
"""A helper for capturing smart server calls for easy debug analysis."""
2311
2357
def _getTestDirPrefix(self):
2312
2358
# create a directory within the top level test directory
2313
if sys.platform == 'win32':
2359
if sys.platform in ('win32', 'cygwin'):
2314
2360
name_prefix = re.sub('[<>*=+",:;_/\\-]', '_', self.id())
2315
2361
# windows is likely to have path-length limits so use a short name
2316
2362
name_prefix = name_prefix[-30:]
2751
2799
bench_history=bench_history,
2752
2800
list_only=list_only,
2802
result_decorators=result_decorators,
2755
2804
runner.stop_on_failure=stop_on_failure
2756
2805
# built in decorator factories:
2764
2813
decorators.append(filter_tests(pattern))
2765
2814
if suite_decorators:
2766
2815
decorators.extend(suite_decorators)
2767
# tell the result object how many tests will be running:
2768
decorators.append(CountingDecorator)
2816
# tell the result object how many tests will be running: (except if
2817
# --parallel=fork is being used. Robert said he will provide a better
2818
# progress design later -- vila 20090817)
2819
if fork_decorator not in decorators:
2820
decorators.append(CountingDecorator)
2769
2821
for decorator in decorators:
2770
2822
suite = decorator(suite)
2771
2823
result = runner.run(suite)
3097
class BZRTransformingResult(unittest.TestResult):
3149
class ForwardingResult(unittest.TestResult):
3099
3151
def __init__(self, target):
3100
3152
unittest.TestResult.__init__(self)
3106
3158
def stopTest(self, test):
3107
3159
self.result.stopTest(test)
3161
def addSkip(self, test, reason):
3162
self.result.addSkip(test, reason)
3164
def addSuccess(self, test):
3165
self.result.addSuccess(test)
3167
def addError(self, test, err):
3168
self.result.addError(test, err)
3170
def addFailure(self, test, err):
3171
self.result.addFailure(test, err)
3174
class BZRTransformingResult(ForwardingResult):
3109
3176
def addError(self, test, err):
3110
3177
feature = self._error_looks_like('UnavailableFeature: ', err)
3111
3178
if feature is not None:
3122
3189
self.result.addFailure(test, err)
3124
def addSkip(self, test, reason):
3125
self.result.addSkip(test, reason)
3127
def addSuccess(self, test):
3128
self.result.addSuccess(test)
3130
3191
def _error_looks_like(self, prefix, err):
3131
3192
"""Deserialize exception and returns the stringify value."""
3208
class ProfileResult(ForwardingResult):
3209
"""Generate profiling data for all activity between start and success.
3211
The profile data is appended to the test's _benchcalls attribute and can
3212
be accessed by the forwarded-to TestResult.
3214
While it might be cleaner do accumulate this in stopTest, addSuccess is
3215
where our existing output support for lsprof is, and this class aims to
3216
fit in with that: while it could be moved it's not necessary to accomplish
3217
test profiling, nor would it be dramatically cleaner.
3220
def startTest(self, test):
3221
self.profiler = bzrlib.lsprof.BzrProfiler()
3222
self.profiler.start()
3223
ForwardingResult.startTest(self, test)
3225
def addSuccess(self, test):
3226
stats = self.profiler.stop()
3228
calls = test._benchcalls
3229
except AttributeError:
3230
test._benchcalls = []
3231
calls = test._benchcalls
3232
calls.append(((test.id(), "", ""), stats))
3233
ForwardingResult.addSuccess(self, test)
3235
def stopTest(self, test):
3236
ForwardingResult.stopTest(self, test)
3237
self.profiler = None
3147
3240
# Controlled by "bzr selftest -E=..." option
3241
# Currently supported:
3242
# -Eallow_debug Will no longer clear debug.debug_flags() so it
3243
# preserves any flags supplied at the command line.
3244
# -Edisable_lock_checks Turns errors in mismatched locks into simple prints
3245
# rather than failing tests. And no longer raise
3246
# LockContention when fctnl locks are not being used
3247
# with proper exclusion rules.
3148
3248
selftest_debug_flags = set()
3185
3287
keep_only = None
3187
3289
keep_only = load_test_id_list(load_list)
3291
starting_with = [test_prefix_alias_registry.resolve_alias(start)
3292
for start in starting_with]
3188
3293
if test_suite_factory is None:
3294
# Reduce loading time by loading modules based on the starting_with
3189
3296
suite = test_suite(keep_only, starting_with)
3191
3298
suite = test_suite_factory()
3300
# But always filter as requested.
3301
suite = filter_suite_by_id_startswith(suite, starting_with)
3302
result_decorators = []
3304
result_decorators.append(ProfileResult)
3192
3305
return run_suite(suite, 'testbzr', verbose=verbose, pattern=pattern,
3193
3306
stop_on_failure=stop_on_failure,
3194
3307
transport=transport,
3202
3315
runner_class=runner_class,
3203
3316
suite_decorators=suite_decorators,
3318
result_decorators=result_decorators,
3206
3321
default_transport = old_transport
3386
3501
'bzrlib.tests.per_lock',
3387
3502
'bzrlib.tests.per_transport',
3388
3503
'bzrlib.tests.per_tree',
3504
'bzrlib.tests.per_pack_repository',
3389
3505
'bzrlib.tests.per_repository',
3390
3506
'bzrlib.tests.per_repository_chk',
3391
3507
'bzrlib.tests.per_repository_reference',
3508
'bzrlib.tests.per_versionedfile',
3392
3509
'bzrlib.tests.per_workingtree',
3393
3510
'bzrlib.tests.test__annotator',
3394
3511
'bzrlib.tests.test__chk_map',
3422
3539
'bzrlib.tests.test_config',
3423
3540
'bzrlib.tests.test_conflicts',
3424
3541
'bzrlib.tests.test_counted_lock',
3542
'bzrlib.tests.test_crash',
3425
3543
'bzrlib.tests.test_decorators',
3426
3544
'bzrlib.tests.test_delta',
3427
3545
'bzrlib.tests.test_debug',
3460
3578
'bzrlib.tests.test_knit',
3461
3579
'bzrlib.tests.test_lazy_import',
3462
3580
'bzrlib.tests.test_lazy_regex',
3581
'bzrlib.tests.test_lock',
3463
3582
'bzrlib.tests.test_lockable_files',
3464
3583
'bzrlib.tests.test_lockdir',
3465
3584
'bzrlib.tests.test_log',
3480
3599
'bzrlib.tests.test_osutils',
3481
3600
'bzrlib.tests.test_osutils_encodings',
3482
3601
'bzrlib.tests.test_pack',
3483
'bzrlib.tests.test_pack_repository',
3484
3602
'bzrlib.tests.test_patch',
3485
3603
'bzrlib.tests.test_patches',
3486
3604
'bzrlib.tests.test_permissions',
3540
3658
'bzrlib.tests.test_urlutils',
3541
3659
'bzrlib.tests.test_version',
3542
3660
'bzrlib.tests.test_version_info',
3543
'bzrlib.tests.test_versionedfile',
3544
3661
'bzrlib.tests.test_weave',
3545
3662
'bzrlib.tests.test_whitebox',
3546
3663
'bzrlib.tests.test_win32utils',
3555
3672
if keep_only is not None:
3556
3673
id_filter = TestIdList(keep_only)
3557
3674
if starting_with:
3558
starting_with = [test_prefix_alias_registry.resolve_alias(start)
3559
for start in starting_with]
3560
3675
# We take precedence over keep_only because *at loading time* using
3561
3676
# both options means we will load less tests for the same final result.
3562
3677
def interesting_module(name):
3638
3753
sys.setdefaultencoding(default_encoding)
3641
suite = filter_suite_by_id_startswith(suite, starting_with)
3643
3755
if keep_only is not None:
3644
3756
# Now that the referred modules have loaded their tests, keep only the
3645
3757
# requested ones.
3774
3886
osutils.rmtree(dirname)
3775
3887
except OSError, e:
3776
if sys.platform == 'win32' and e.errno == errno.EACCES:
3777
sys.stderr.write('Permission denied: '
3778
'unable to remove testing dir '
3780
% (os.path.basename(dirname), e))
3888
# We don't want to fail here because some useful display will be lost
3889
# otherwise. Polluting the tmp dir is bad, but not giving all the
3890
# possible info to the test runner is even worse.
3891
sys.stderr.write('Unable to remove testing dir %s\n%s'
3892
% (os.path.basename(dirname), e))
3785
3895
class Feature(object):