From ee4d848e987b1b5a2173d3ada31f5687453ed3c7 Mon Sep 17 00:00:00 2001 From: Anna Eilering Date: Mon, 25 Apr 2016 18:30:26 -0500 Subject: [PATCH] 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 --- cafe/drivers/base.py | 4 ++-- cafe/drivers/unittest/fixtures.py | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cafe/drivers/base.py b/cafe/drivers/base.py index 297f68b..1272cb0 100644 --- a/cafe/drivers/base.py +++ b/cafe/drivers/base.py @@ -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), diff --git a/cafe/drivers/unittest/fixtures.py b/cafe/drivers/unittest/fixtures.py index f946598..9238a84 100644 --- a/cafe/drivers/unittest/fixtures.py +++ b/cafe/drivers/unittest/fixtures.py @@ -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,