aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2017-05-19 11:29:26 +0200
committerCédric Ollivier <cedric.ollivier@orange.com>2017-05-19 11:44:28 +0200
commit5873cb24ff67b9f878db312d98187aaec05b5bd7 (patch)
treec68879dc6277c2b34e416bbcad2263a1cf90b0db
parentd56d208fdf7bdb28c03e239b2579f7af25c33700 (diff)
Fully cover pytest_suite_runner.py
Change-Id: I766afb1d5c6ef53a5b551539662ee363ae8eadee Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
-rw-r--r--functest/tests/unit/core/test_pytest_suite_runner.py42
1 files changed, 36 insertions, 6 deletions
diff --git a/functest/tests/unit/core/test_pytest_suite_runner.py b/functest/tests/unit/core/test_pytest_suite_runner.py
index 4160df039..f317cdea2 100644
--- a/functest/tests/unit/core/test_pytest_suite_runner.py
+++ b/functest/tests/unit/core/test_pytest_suite_runner.py
@@ -21,25 +21,32 @@ class PyTestSuiteRunnerTesting(unittest.TestCase):
def setUp(self):
self.psrunner = pytest_suite_runner.PyTestSuiteRunner()
- def _test_run(self, result, status=testcase.TestCase.EX_OK):
+ @mock.patch('unittest.TestLoader')
+ def _test_run(self, mock_class=None, result=mock.Mock(),
+ status=testcase.TestCase.EX_OK):
with mock.patch('functest.core.pytest_suite_runner.'
'unittest.TextTestRunner.run',
return_value=result):
self.assertEqual(self.psrunner.run(), status)
+ mock_class.assert_not_called()
+
+ def test_check_suite_null(self):
+ self.assertEqual(self.psrunner.suite, None)
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._test_run(result=mock_result,
+ status=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):
+ def test_run_result_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._test_run(result=mock_result)
self.assertEqual(self.psrunner.result, 96)
self.assertEqual(self.psrunner.details,
{'errors': [('test1', 'error_msg1')],
@@ -47,15 +54,38 @@ class PyTestSuiteRunnerTesting(unittest.TestCase):
self.assertEqual(self.psrunner.is_successful(),
testcase.TestCase.EX_TESTCASE_FAILED)
- def test_run_ok(self):
+ def test_run_result_ok(self):
mock_result = mock.Mock(testsRun=50, errors=[],
failures=[])
- self._test_run(mock_result)
+ self._test_run(result=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)
+ @mock.patch('unittest.TestLoader')
+ def test_run_name_exc(self, mock_class=None):
+ mock_obj = mock.Mock(side_effect=ImportError)
+ mock_class.side_effect = mock_obj
+ self.assertEqual(self.psrunner.run(name='foo'),
+ testcase.TestCase.EX_RUN_ERROR)
+ mock_class.assert_called_once_with()
+ mock_obj.assert_called_once_with()
+
+ @mock.patch('unittest.TestLoader')
+ def test_run_name(self, mock_class=None):
+ mock_result = mock.Mock(testsRun=50, errors=[],
+ failures=[])
+ mock_obj = mock.Mock()
+ mock_class.side_effect = mock_obj
+ with mock.patch('functest.core.pytest_suite_runner.'
+ 'unittest.TextTestRunner.run',
+ return_value=mock_result):
+ self.assertEqual(self.psrunner.run(name='foo'),
+ testcase.TestCase.EX_OK)
+ mock_class.assert_called_once_with()
+ mock_obj.assert_called_once_with()
+
if __name__ == "__main__":
logging.disable(logging.CRITICAL)