diff options
author | 2017-05-22 13:07:45 +0000 | |
---|---|---|
committer | 2017-05-22 13:07:45 +0000 | |
commit | 5509d6b06cc77ecd913761b534db3951eb9777bd (patch) | |
tree | a59172da60993f5af5b718396f9f2a09aadc4f4c /functest/tests | |
parent | ec4514f240836129d5f3c25b4708d73a65b9cb60 (diff) | |
parent | d56d208fdf7bdb28c03e239b2579f7af25c33700 (diff) |
Merge "Precise self.result in pytest_suite_runner.py"
Diffstat (limited to 'functest/tests')
-rw-r--r-- | functest/tests/unit/core/test_pytest_suite_runner.py | 52 |
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__": |