Define logger as Feature instance attribute
[functest.git] / functest / tests / unit / core / test_feature.py
index 993da5a..988981e 100644 (file)
@@ -17,10 +17,6 @@ import mock
 from functest.core import feature
 from functest.core import testcase
 
-# logging must be disabled else it calls time.time()
-# what will break these unit tests.
-logging.disable(logging.CRITICAL)
-
 
 class FeatureTestingBase(unittest.TestCase):
 
@@ -28,7 +24,7 @@ class FeatureTestingBase(unittest.TestCase):
     _project_name = "bar"
     _repo = "dir_repo_copper"
     _cmd = "cd /home/opnfv/repos/foo/tests && bash run.sh && cd -"
-    _output_file = '/home/opnfv/functest/results/bar.log'
+    _output_file = '/home/opnfv/functest/results/foo.log'
     feature = None
 
     @mock.patch('time.time', side_effect=[1, 2])
@@ -42,12 +38,26 @@ class FeatureTestingBase(unittest.TestCase):
         self.assertEqual(self.feature.start_time, 1)
         self.assertEqual(self.feature.stop_time, 2)
 
+    def test_logger_module_ko(self):
+        with mock.patch('six.moves.builtins.open'):
+            self.feature = feature.Feature(
+                project_name=self._project_name, case_name=self._case_name)
+            self.assertEqual(self.feature.logger.name, self._case_name)
+
+    def test_logger_module(self):
+        with mock.patch('six.moves.builtins.open'):
+            self.feature = feature.Feature(
+                project_name=self._project_name, case_name=self._case_name,
+                run={'module': 'bar'})
+            self.assertEqual(self.feature.logger.name, 'bar')
+
 
 class FeatureTesting(FeatureTestingBase):
 
     def setUp(self):
-        self.feature = feature.Feature(
-            project_name=self._project_name, case_name=self._case_name)
+        with mock.patch('six.moves.builtins.open'):
+            self.feature = feature.Feature(
+                project_name=self._project_name, case_name=self._case_name)
 
     def test_run_exc(self):
         # pylint: disable=bad-continuation
@@ -64,8 +74,9 @@ class FeatureTesting(FeatureTestingBase):
 class BashFeatureTesting(FeatureTestingBase):
 
     def setUp(self):
-        self.feature = feature.BashFeature(
-            project_name=self._project_name, case_name=self._case_name)
+        with mock.patch('six.moves.builtins.open'):
+            self.feature = feature.BashFeature(
+                project_name=self._project_name, case_name=self._case_name)
 
     @mock.patch("functest.utils.functest_utils.execute_command")
     def test_run_no_cmd(self, mock_method=None):
@@ -95,4 +106,7 @@ class BashFeatureTesting(FeatureTestingBase):
 
 
 if __name__ == "__main__":
+    # logging must be disabled else it calls time.time()
+    # what will break these unit tests.
+    logging.disable(logging.CRITICAL)
     unittest.main(verbosity=2)