Commits

Denis Bilenko  committed f561b7e

greentest.py: fix switch_count property in case when CountingHub is not installed

it used to raise an error while it should return None

  • Participants
  • Parent commits 47440a8

Comments (0)

Files changed (1)

File greentest/greentest.py

         return BaseTestCase.run(self, *args, **kwargs)
 
     def setUp(self):
-        self.initial_switch_count = getattr(_get_hub(), 'switch_count', 0)
+        self.initial_switch_count = getattr(_get_hub(), 'switch_count', None)
 
     def tearDown(self):
         if hasattr(self, 'cleanup'):
     def switch_count(self):
         if self.switch_expected is None:
             return
-        initial = getattr(self, 'initial_switch_count', None)
-        if initial is None:
+        if not hasattr(self, 'initial_switch_count'):
             raise AssertionError('Cannot check switch_count (setUp() was not called)')
+        if self.initial_switch_count is None:
+            return
         current = getattr(_get_hub(), 'switch_count', 0)
-        return current - initial
+        return current - self.initial_switch_count
 
     @property
     def testname(self):