From b7896a14755f9dc4c8e4ba234379e82b64dbda67 Mon Sep 17 00:00:00 2001 From: "halil.cakal" Date: Wed, 25 Jan 2023 17:24:45 +0000 Subject: [PATCH] Introduce test suite for unit test cases, implement automaic way of finding the tests Issue-ID: NONRTRIC-817 Change-Id: I816ef79523af2faf99d12dab1dd14a821c191861 Signed-off-by: halil.cakal --- catalogue-enhanced/tests/suite.py | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 catalogue-enhanced/tests/suite.py diff --git a/catalogue-enhanced/tests/suite.py b/catalogue-enhanced/tests/suite.py new file mode 100644 index 0000000..7d82b20 --- /dev/null +++ b/catalogue-enhanced/tests/suite.py @@ -0,0 +1,49 @@ +# ============LICENSE_START=============================================== +# Copyright (C) 2023 Nordix Foundation. All rights reserved. +# ======================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END================================================= +# + +# Combining all unit tests in one place + +import os +import sys +import unittest + +# Includes project source files +def setup_env(): + cwd=os.getcwd()+"/" + sys.path.append(os.path.abspath(cwd+'../src')) + +# Returns unit test cases from test modules +def suite(): + setup_env() + suite= unittest.TestSuite() + + modules_to_test= [] + files= os.listdir('.') + for afile in files: + if afile.startswith('test') and afile.endswith('.py') and afile!= 'test_catalogue_enhanced.py': + modules_to_test.append(afile.replace('.py', '')) + + for module in map(__import__, modules_to_test): + tests= unittest.findTestCases(module) + for test in tests: + suite.addTest(test) + + return suite + +if __name__ == '__main__': + runner= unittest.TextTestRunner() + runner.run(suite()) -- 2.16.6