Update Xtesting to 0.61 79/66079/3
authorCédric Ollivier <cedric.ollivier@orange.com>
Thu, 27 Dec 2018 15:18:51 +0000 (16:18 +0100)
committerCédric Ollivier <cedric.ollivier@orange.com>
Thu, 27 Dec 2018 17:38:40 +0000 (18:38 +0100)
It now generates html reports for unit tests (snaps).

Change-Id: Ica8fab2b383723957c1068c5accbcab9568002ac
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
(cherry picked from commit 98ee1837b939f32c2c3bc17787065d0bf0a22c3f)

functest/tests/unit/openstack/snaps/test_snaps.py
upper-constraints.txt

index 14bc385..db8e3e0 100644 (file)
@@ -40,36 +40,45 @@ class APICheckTesting(unittest.TestCase):
         mock_shade.assert_called()
         mock_new_project.assert_called()
 
+    @mock.patch('xtesting.core.unit.Suite.generate_html')
+    @mock.patch('xtesting.core.unit.Suite.generate_xunit')
+    @mock.patch('xtesting.core.unit.Suite.generate_stats')
+    @mock.patch('os.path.isdir', return_value=True)
+    @mock.patch('unittest.TestLoader')
     @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
                 'add_openstack_client_tests')
     @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
                 'add_openstack_api_tests')
-    @mock.patch('unittest.TextTestRunner.run',
-                return_value=mock.MagicMock(name='unittest.TextTestResult'))
+    @mock.patch('subunit.run.SubunitTestRunner.run')
     def test_run_success(self, *args):
-        args[0].return_value.testsRun = 100
-        args[0].return_value.failures = []
-        args[0].return_value.errors = []
-        self.assertEquals(testcase.TestCase.EX_OK, self.api_check.run())
-        self.assertEquals(
+        args[0].return_value = mock.Mock(
+            decorated=mock.Mock(
+                testsRun=100, errors=[], failures=[]))
+        with mock.patch('six.moves.builtins.open', mock.mock_open()):
+            self.assertEqual(testcase.TestCase.EX_OK, self.api_check.run())
+        self.assertEqual(
             testcase.TestCase.EX_OK, self.api_check.is_successful())
         args[0].assert_called_with(mock.ANY)
         args[1].assert_called_with(
             ext_net_name='foo', image_metadata=mock.ANY,
             os_creds=self.os_creds, suite=mock.ANY, use_keystone=True)
 
+    @mock.patch('xtesting.core.unit.Suite.generate_html')
+    @mock.patch('xtesting.core.unit.Suite.generate_xunit')
+    @mock.patch('xtesting.core.unit.Suite.generate_stats')
+    @mock.patch('os.path.isdir', return_value=True)
     @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
                 'add_openstack_client_tests')
     @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
                 'add_openstack_api_tests')
-    @mock.patch('unittest.TextTestRunner.run',
-                return_value=mock.MagicMock(name='unittest.TextTestResult'))
+    @mock.patch('subunit.run.SubunitTestRunner.run')
     def test_run_1_of_100_ko(self, *args):
-        args[0].return_value.testsRun = 100
-        args[0].return_value.failures = ['foo']
-        args[0].return_value.errors = []
-        self.assertEquals(testcase.TestCase.EX_OK, self.api_check.run())
-        self.assertEquals(
+        args[0].return_value = mock.Mock(
+            decorated=mock.Mock(
+                testsRun=100, errors=[], failures=['foo']))
+        with mock.patch('six.moves.builtins.open', mock.mock_open()):
+            self.assertEqual(testcase.TestCase.EX_OK, self.api_check.run())
+        self.assertEqual(
             testcase.TestCase.EX_TESTCASE_FAILED,
             self.api_check.is_successful())
         args[0].assert_called_with(mock.ANY)
@@ -77,19 +86,23 @@ class APICheckTesting(unittest.TestCase):
             ext_net_name='foo', image_metadata=mock.ANY,
             os_creds=self.os_creds, suite=mock.ANY, use_keystone=True)
 
+    @mock.patch('xtesting.core.unit.Suite.generate_html')
+    @mock.patch('xtesting.core.unit.Suite.generate_xunit')
+    @mock.patch('xtesting.core.unit.Suite.generate_stats')
+    @mock.patch('os.path.isdir', return_value=True)
     @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
                 'add_openstack_client_tests')
     @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
                 'add_openstack_api_tests')
-    @mock.patch('unittest.TextTestRunner.run',
-                return_value=mock.MagicMock(name='unittest.TextTestResult'))
+    @mock.patch('subunit.run.SubunitTestRunner.run')
     def test_run_1_of_100_ko_criteria(self, *args):
         self.api_check.criteria = 90
-        args[0].return_value.testsRun = 100
-        args[0].return_value.failures = ['foo']
-        args[0].return_value.errors = []
-        self.assertEquals(testcase.TestCase.EX_OK, self.api_check.run())
-        self.assertEquals(
+        args[0].return_value = mock.Mock(
+            decorated=mock.Mock(
+                testsRun=100, errors=[], failures=['foo']))
+        with mock.patch('six.moves.builtins.open', mock.mock_open()):
+            self.assertEqual(testcase.TestCase.EX_OK, self.api_check.run())
+        self.assertEqual(
             testcase.TestCase.EX_OK, self.api_check.is_successful())
         args[0].assert_called_with(mock.ANY)
         args[1].assert_called_with(
@@ -117,16 +130,20 @@ class HealthCheckTesting(unittest.TestCase):
         mock_shade.assert_called()
         mock_new_project.assert_called()
 
+    @mock.patch('xtesting.core.unit.Suite.generate_html')
+    @mock.patch('xtesting.core.unit.Suite.generate_xunit')
+    @mock.patch('xtesting.core.unit.Suite.generate_stats')
+    @mock.patch('os.path.isdir', return_value=True)
     @mock.patch('snaps.openstack.tests.os_source_file_test.'
                 'OSIntegrationTestCase.parameterize')
-    @mock.patch('unittest.TextTestRunner.run',
-                return_value=mock.MagicMock(name='unittest.TextTestResult'))
+    @mock.patch('subunit.run.SubunitTestRunner.run')
     def test_run_success(self, *args):
-        args[0].return_value.testsRun = 100
-        args[0].return_value.failures = []
-        args[0].return_value.errors = []
-        self.assertEquals(testcase.TestCase.EX_OK, self.health_check.run())
-        self.assertEquals(
+        args[0].return_value = mock.Mock(
+            decorated=mock.Mock(
+                testsRun=100, errors=[], failures=[]))
+        with mock.patch('six.moves.builtins.open', mock.mock_open()):
+            self.assertEqual(testcase.TestCase.EX_OK, self.health_check.run())
+        self.assertEqual(
             testcase.TestCase.EX_OK, self.health_check.is_successful())
         args[0].assert_called_with(mock.ANY)
         args[1].assert_called_with(
@@ -134,16 +151,20 @@ class HealthCheckTesting(unittest.TestCase):
             image_metadata=mock.ANY, netconf_override=None,
             os_creds=self.os_creds, use_keystone=True)
 
+    @mock.patch('xtesting.core.unit.Suite.generate_html')
+    @mock.patch('xtesting.core.unit.Suite.generate_xunit')
+    @mock.patch('xtesting.core.unit.Suite.generate_stats')
+    @mock.patch('os.path.isdir', return_value=True)
     @mock.patch('snaps.openstack.tests.os_source_file_test.'
                 'OSIntegrationTestCase.parameterize')
-    @mock.patch('unittest.TextTestRunner.run',
-                return_value=mock.MagicMock(name='unittest.TextTestResult'))
+    @mock.patch('subunit.run.SubunitTestRunner.run')
     def test_run_1_of_100_ko(self, *args):
-        args[0].return_value.testsRun = 100
-        args[0].return_value.failures = ['foo']
-        args[0].return_value.errors = []
-        self.assertEquals(testcase.TestCase.EX_OK, self.health_check.run())
-        self.assertEquals(
+        args[0].return_value = mock.Mock(
+            decorated=mock.Mock(
+                testsRun=100, errors=[], failures=['foo']))
+        with mock.patch('six.moves.builtins.open', mock.mock_open()):
+            self.assertEqual(testcase.TestCase.EX_OK, self.health_check.run())
+        self.assertEqual(
             testcase.TestCase.EX_TESTCASE_FAILED,
             self.health_check.is_successful())
         args[0].assert_called_with(mock.ANY)
@@ -152,17 +173,21 @@ class HealthCheckTesting(unittest.TestCase):
             image_metadata=mock.ANY, netconf_override=None,
             os_creds=self.os_creds, use_keystone=True)
 
+    @mock.patch('xtesting.core.unit.Suite.generate_html')
+    @mock.patch('xtesting.core.unit.Suite.generate_xunit')
+    @mock.patch('xtesting.core.unit.Suite.generate_stats')
+    @mock.patch('os.path.isdir', return_value=True)
     @mock.patch('snaps.openstack.tests.os_source_file_test.'
                 'OSIntegrationTestCase.parameterize')
-    @mock.patch('unittest.TextTestRunner.run',
-                return_value=mock.MagicMock(name='unittest.TextTestResult'))
+    @mock.patch('subunit.run.SubunitTestRunner.run')
     def test_run_1_of_100_ko_criteria(self, *args):
         self.health_check.criteria = 90
-        args[0].return_value.testsRun = 100
-        args[0].return_value.failures = ['foo']
-        args[0].return_value.errors = []
-        self.assertEquals(testcase.TestCase.EX_OK, self.health_check.run())
-        self.assertEquals(
+        args[0].return_value = mock.Mock(
+            decorated=mock.Mock(
+                testsRun=100, errors=[], failures=['foo']))
+        with mock.patch('six.moves.builtins.open', mock.mock_open()):
+            self.assertEqual(testcase.TestCase.EX_OK, self.health_check.run())
+        self.assertEqual(
             testcase.TestCase.EX_OK, self.health_check.is_successful())
         args[0].assert_called_with(mock.ANY)
         args[1].assert_called_with(
@@ -191,16 +216,20 @@ class SmokeTesting(unittest.TestCase):
         mock_shade.assert_called()
         mock_new_project.assert_called()
 
+    @mock.patch('xtesting.core.unit.Suite.generate_html')
+    @mock.patch('xtesting.core.unit.Suite.generate_xunit')
+    @mock.patch('xtesting.core.unit.Suite.generate_stats')
+    @mock.patch('os.path.isdir', return_value=True)
     @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
                 'add_openstack_integration_tests')
-    @mock.patch('unittest.TextTestRunner.run',
-                return_value=mock.MagicMock(name='unittest.TextTestResult'))
+    @mock.patch('subunit.run.SubunitTestRunner.run')
     def test_run_success(self, *args):
-        args[0].return_value.testsRun = 100
-        args[0].return_value.failures = []
-        args[0].return_value.errors = []
-        self.assertEquals(testcase.TestCase.EX_OK, self.smoke.run())
-        self.assertEquals(testcase.TestCase.EX_OK, self.smoke.is_successful())
+        args[0].return_value = mock.Mock(
+            decorated=mock.Mock(
+                testsRun=100, errors=[], failures=[]))
+        with mock.patch('six.moves.builtins.open', mock.mock_open()):
+            self.assertEqual(testcase.TestCase.EX_OK, self.smoke.run())
+        self.assertEqual(testcase.TestCase.EX_OK, self.smoke.is_successful())
         args[0].assert_called_with(mock.ANY)
         args[1].assert_called_with(
             ext_net_name='foo', flavor_metadata=mock.ANY,
@@ -208,16 +237,20 @@ class SmokeTesting(unittest.TestCase):
             os_creds=self.os_creds, suite=mock.ANY, use_floating_ips=True,
             use_keystone=True)
 
+    @mock.patch('xtesting.core.unit.Suite.generate_html')
+    @mock.patch('xtesting.core.unit.Suite.generate_xunit')
+    @mock.patch('xtesting.core.unit.Suite.generate_stats')
+    @mock.patch('os.path.isdir', return_value=True)
     @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
                 'add_openstack_integration_tests')
-    @mock.patch('unittest.TextTestRunner.run',
-                return_value=mock.MagicMock(name='unittest.TextTestResult'))
+    @mock.patch('subunit.run.SubunitTestRunner.run')
     def test_run_1_of_100_ko(self, *args):
-        args[0].return_value.testsRun = 100
-        args[0].return_value.failures = ['foo']
-        args[0].return_value.errors = []
-        self.assertEquals(testcase.TestCase.EX_OK, self.smoke.run())
-        self.assertEquals(
+        args[0].return_value = mock.Mock(
+            decorated=mock.Mock(
+                testsRun=100, errors=[], failures=['foo']))
+        with mock.patch('six.moves.builtins.open', mock.mock_open()):
+            self.assertEqual(testcase.TestCase.EX_OK, self.smoke.run())
+        self.assertEqual(
             testcase.TestCase.EX_TESTCASE_FAILED, self.smoke.is_successful())
         args[0].assert_called_with(mock.ANY)
         args[1].assert_called_with(
@@ -226,17 +259,21 @@ class SmokeTesting(unittest.TestCase):
             os_creds=self.os_creds, suite=mock.ANY, use_floating_ips=True,
             use_keystone=True)
 
+    @mock.patch('xtesting.core.unit.Suite.generate_html')
+    @mock.patch('xtesting.core.unit.Suite.generate_xunit')
+    @mock.patch('xtesting.core.unit.Suite.generate_stats')
+    @mock.patch('os.path.isdir', return_value=True)
     @mock.patch('functest.opnfv_tests.openstack.snaps.snaps_suite_builder.'
                 'add_openstack_integration_tests')
-    @mock.patch('unittest.TextTestRunner.run',
-                return_value=mock.MagicMock(name='unittest.TextTestResult'))
+    @mock.patch('subunit.run.SubunitTestRunner.run')
     def test_run_1_of_100_ko_criteria(self, *args):
         self.smoke.criteria = 90
-        args[0].return_value.testsRun = 100
-        args[0].return_value.failures = ['foo']
-        args[0].return_value.errors = []
-        self.assertEquals(testcase.TestCase.EX_OK, self.smoke.run())
-        self.assertEquals(
+        args[0].return_value = mock.Mock(
+            decorated=mock.Mock(
+                testsRun=100, errors=[], failures=['foo']))
+        with mock.patch('six.moves.builtins.open', mock.mock_open()):
+            self.assertEqual(testcase.TestCase.EX_OK, self.smoke.run())
+        self.assertEqual(
             testcase.TestCase.EX_OK, self.smoke.is_successful())
         args[0].assert_called_with(mock.ANY)
         args[1].assert_called_with(
index b5ad2b4..5c7991e 100644 (file)
@@ -13,6 +13,6 @@ robotframework-httplibrary===0.4.2
 robotframework-requests===0.4.7
 robotframework-sshlibrary===2.1.3;python_version=='2.7'
 ansible===2.3.2.0
-xtesting===0.60.0
+xtesting===0.61.0
 networking-bgpvpn===8.0.0
 networking-sfc===6.0.0