aboutsummaryrefslogtreecommitdiffstats
path: root/functest/tests
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2017-05-19 08:04:12 +0200
committerCédric Ollivier <cedric.ollivier@orange.com>2017-05-19 11:44:06 +0200
commitd56d208fdf7bdb28c03e239b2579f7af25c33700 (patch)
tree0e28b92f1288fbd2ffc2f7701d9e29faf343d4f0 /functest/tests
parented88e5e9abb8c24cee2507b62a45878637411c25 (diff)
Precise self.result in pytest_suite_runner.py
It also adds the related unit tests. Change-Id: I8325bd9a55c69b229e3c48a9e64aa963e685e03d Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
Diffstat (limited to 'functest/tests')
-rw-r--r--functest/tests/unit/core/test_pytest_suite_runner.py52
1 files changed, 32 insertions, 20 deletions
diff --git a/functest/tests/unit/core/test_pytest_suite_runner.py b/functest/tests/unit/core/test_pytest_suite_runner.py
index 07ac7906..4160df03 100644
--- a/functest/tests/unit/core/test_pytest_suite_runner.py
+++ b/functest/tests/unit/core/test_pytest_suite_runner.py
@@ -20,29 +20,41 @@ class PyTestSuiteRunnerTesting(unittest.TestCase):
def setUp(self):
self.psrunner = pytest_suite_runner.PyTestSuiteRunner()
- self.result = mock.Mock()
- attrs = {'errors': [('test1', 'error_msg1')],
- 'failures': [('test2', 'failure_msg1')]}
- self.result.configure_mock(**attrs)
-
- self.pass_results = mock.Mock()
- attrs = {'errors': None,
- 'failures': None}
- self.pass_results.configure_mock(**attrs)
-
- def test_run(self):
- self.psrunner.case_name = 'test_case_name'
- with mock.patch('functest.core.pytest_suite_runner.'
- 'unittest.TextTestRunner.run',
- return_value=self.result):
- self.assertEqual(self.psrunner.run(),
- testcase.TestCase.EX_OK)
+ def _test_run(self, result, status=testcase.TestCase.EX_OK):
with mock.patch('functest.core.pytest_suite_runner.'
'unittest.TextTestRunner.run',
- return_value=self.pass_results):
- self.assertEqual(self.psrunner.run(),
- testcase.TestCase.EX_OK)
+ return_value=result):
+ self.assertEqual(self.psrunner.run(), status)
+
+ def test_run_no_ut(self):
+ mock_result = mock.Mock(testsRun=0, errors=[], failures=[])
+ self._test_run(mock_result, testcase.TestCase.EX_RUN_ERROR)
+ self.assertEqual(self.psrunner.result, 0)
+ self.assertEqual(self.psrunner.details, {'errors': [], 'failures': []})
+ self.assertEqual(self.psrunner.is_successful(),
+ testcase.TestCase.EX_TESTCASE_FAILED)
+
+ def test_run_ko(self):
+ self.psrunner.criteria = 100
+ mock_result = mock.Mock(testsRun=50, errors=[('test1', 'error_msg1')],
+ failures=[('test2', 'failure_msg1')])
+ self._test_run(mock_result, testcase.TestCase.EX_OK)
+ self.assertEqual(self.psrunner.result, 96)
+ self.assertEqual(self.psrunner.details,
+ {'errors': [('test1', 'error_msg1')],
+ 'failures': [('test2', 'failure_msg1')]})
+ self.assertEqual(self.psrunner.is_successful(),
+ testcase.TestCase.EX_TESTCASE_FAILED)
+
+ def test_run_ok(self):
+ mock_result = mock.Mock(testsRun=50, errors=[],
+ failures=[])
+ self._test_run(mock_result)
+ self.assertEqual(self.psrunner.result, 100)
+ self.assertEqual(self.psrunner.details, {'errors': [], 'failures': []})
+ self.assertEqual(self.psrunner.is_successful(),
+ testcase.TestCase.EX_OK)
if __name__ == "__main__":