Merge "Added Safety and clarity around tests setups missing Super()"

This commit is contained in:
Jenkins 2016-05-02 02:06:16 +00:00 committed by Gerrit Code Review
commit 8823a48b7e
2 changed files with 12 additions and 5 deletions

View File

@ -115,9 +115,9 @@ class FixtureReporter(object):
self.test_metrics.timer.stop()
except AttributeError:
warn(
"Test metrics not being logged!"
"\nTest metrics not being logged! "
"stop_test_metrics is being called without "
"start_test_metrics having been previously called.")
"start_test_metrics having been previously called.\n\n")
log_info_block(
self.logger.log,
[('Test Case', test_name),

View File

@ -123,9 +123,16 @@ class BaseTestFixture(unittest.TestCase):
else:
self._reporter.stop_test_metrics(self._testMethodName,
'Passed')
self._duration = \
self._reporter.test_metrics.timer.get_elapsed_time()
try:
self._duration = \
self._reporter.test_metrics.timer.get_elapsed_time()
except AttributeError:
# If the reporter was not appropriately called at test start
# or end tests will fail unless we catch this. This is common
# in the case where test writers did not appropriately call
# 'super' in the setUp or setUpClass of their fixture or
# test class.
self._duration = float('nan')
else:
for method, _ in self._outcome.errors:
if self._test_name_matches_result(self._testMethodName,