Added Safety and clarity around tests setups missing Super()

Test setUp methods that do not have a 'super()' call will
fail and cause the entire suite to fail despite tests
passing. Runner failures should, whenever possible, not
interfere with test results.

This is to add a try/except around getting the '_duration'
value for tests. If a test uses a setUp() method without super
it will recieve 'NaN' as a 'duration' and the user will
recieve a warning in console output but will not recieve
failures.

This is considered a safety mechanism intended to provide
test writers time to update their tests using 'setUp()' to
correctly call super().

Additionally added some newlines around the warning so that it is
very clear that there is an issue.

Change-Id: I32d2352ff7081b84383835bcc8812e37735c68d2
This commit is contained in:
Anna Eilering 2016-04-25 18:30:26 -05:00
parent 0a7a3940e6
commit ee4d848e98
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,