aboutsummaryrefslogtreecommitdiffstats
path: root/functest
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2017-05-23 19:07:52 +0200
committerCédric Ollivier <cedric.ollivier@orange.com>2017-05-29 12:03:44 +0200
commit34b2583ee5509daf8b237a9c55173026ad42b2bc (patch)
treee98053ccef15397ae3700e5c6dbaecdc85c15148 /functest
parentac816628995c1e017f12ba23435ae07d24ceecac (diff)
Protect against self.suite = None
Change-Id: Ie3370ebfdd51b9aff707e50b754ca52796e49fbf Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
Diffstat (limited to 'functest')
-rw-r--r--functest/core/unit.py20
-rw-r--r--functest/tests/unit/core/test_unit.py6
2 files changed, 17 insertions, 9 deletions
diff --git a/functest/core/unit.py b/functest/core/unit.py
index 6799420c..5c4d2006 100644
--- a/functest/core/unit.py
+++ b/functest/core/unit.py
@@ -65,20 +65,24 @@ class Suite(testcase.TestCase):
return testcase.TestCase.EX_RUN_ERROR
except KeyError:
pass
- self.start_time = time.time()
- stream = six.StringIO()
- result = unittest.TextTestRunner(
- stream=stream, verbosity=2).run(self.suite)
- self.logger.debug("\n\n%s", stream.getvalue())
- self.stop_time = time.time()
- self.details = {"failures": result.failures,
- "errors": result.errors}
try:
+ assert self.suite
+ self.start_time = time.time()
+ stream = six.StringIO()
+ result = unittest.TextTestRunner(
+ stream=stream, verbosity=2).run(self.suite)
+ self.logger.debug("\n\n%s", stream.getvalue())
+ self.stop_time = time.time()
+ self.details = {"failures": result.failures,
+ "errors": result.errors}
self.result = 100 * (
(result.testsRun - (len(result.failures) +
len(result.errors))) /
result.testsRun)
return testcase.TestCase.EX_OK
+ except AssertionError:
+ self.logger.error("No suite is defined")
+ return testcase.TestCase.EX_RUN_ERROR
except ZeroDivisionError:
self.logger.error("No test has been run")
return testcase.TestCase.EX_RUN_ERROR
diff --git a/functest/tests/unit/core/test_unit.py b/functest/tests/unit/core/test_unit.py
index f86ea8d3..79c4e7d7 100644
--- a/functest/tests/unit/core/test_unit.py
+++ b/functest/tests/unit/core/test_unit.py
@@ -20,6 +20,7 @@ class PyTestSuiteRunnerTesting(unittest.TestCase):
def setUp(self):
self.psrunner = unit.Suite()
+ self.psrunner.suite = "foo"
@mock.patch('unittest.TestLoader')
def _test_run(self, mock_class=None, result=mock.Mock(),
@@ -30,7 +31,10 @@ class PyTestSuiteRunnerTesting(unittest.TestCase):
mock_class.assert_not_called()
def test_check_suite_null(self):
- self.assertEqual(self.psrunner.suite, None)
+ self.assertEqual(unit.Suite().suite, None)
+ self.psrunner.suite = None
+ self._test_run(result=mock.Mock(),
+ status=testcase.TestCase.EX_RUN_ERROR)
def test_run_no_ut(self):
mock_result = mock.Mock(testsRun=0, errors=[], failures=[])