summaryrefslogtreecommitdiffstats
path: root/rpm/rootfs-scripts/run_tests.py
diff options
context:
space:
mode:
authorQiu Tingting <qiutt@fujitsu.com>2022-05-26 13:48:51 +0800
committerQiu Tingting <qiutt@fujitsu.com>2022-05-26 13:48:51 +0800
commitdaed111bea534c63ed6906e8e0c1b5578e324838 (patch)
treed6245a713b21bd494469a38ac18d31e35cb01f16 /rpm/rootfs-scripts/run_tests.py
parent3956e11df8cff8bc2e8feb4564b63c13daf27f49 (diff)
qa-test-misc: rewrite rpm tests with AGLBaseTest class
Rewrite the run_tests.py with AGLBaseTest class added in agl-test-framework. Delete the parser.py and report.py. Bug-AGL: SPEC-4345 Signed-off-by: Qiu Tingting <qiutt@fujitsu.com> Change-Id: If86c283f6f207fe08912acb7e5e1b754fcb5ea36
Diffstat (limited to 'rpm/rootfs-scripts/run_tests.py')
-rw-r--r--rpm/rootfs-scripts/run_tests.py85
1 files changed, 46 insertions, 39 deletions
diff --git a/rpm/rootfs-scripts/run_tests.py b/rpm/rootfs-scripts/run_tests.py
index 8b085c6..c751faf 100644
--- a/rpm/rootfs-scripts/run_tests.py
+++ b/rpm/rootfs-scripts/run_tests.py
@@ -2,53 +2,60 @@ import pytest
import subprocess
import plugins.agl_test_utils as agl_test_utils
-import plugins.agl_test_conf as agl_test_conf
-import rpm.parser as parser
-import rpm.report as report
-
-WORK_DIR = agl_test_conf.WORK_DIR
-TMP_LOGS_DIR = agl_test_conf.TMP_LOGS_DIR
-
-THIS_TEST = "rpm"
-test_cases_values_and_status = []
-
-def setup_module():
+from plugins.agl_test_base import AGLBaseTest
+class RPMBase(AGLBaseTest):
+ def __init__(self):
+ super().__init__(name="rpm")
+
+ def run_case(self, case_id):
+ case_info = self.get_caseinfo_by_name(case_id)
+ if (case_info[1] == "TEST-PASS"):
+ case_info[2] = "passed"
+ else:
+ case_info[2] == "failed"
+ self.update_caseinfo_by_name(case_id, case_info)
+ assert case_info[2] == "passed"
+
+ #Run test, and redirect the log into the file of rpm.log
+ def run_test_fun(self):
+ log_file = self.get_logfile()
+ cwd = self.get_workdir()
+ with open(log_file,'w') as log_f:
+ subprocess.run(['sh','rpm_test.sh'],cwd=cwd,stdout=log_f,stderr=log_f)
+ log_f.close()
+
+@pytest.fixture(scope='module')
+def testbase():
+ #init instance for test
+ instance = RPMBase()
+ #run test scripts
+ instance.run_test_fun()
+ #parser log
+ instance.log_process()
+
+ yield instance
+
+ #package log files and make report file
+ instance.log_report()
+
+def setup_module(testbase: RPMBase):
agl_test_utils.find_cmd("rpm")
- agl_test_utils.create_dir(THIS_TEST)
- run_test_fun()
- global test_cases_values_and_status
- test_cases_values_and_status = parser.log_process(TMP_LOGS_DIR,THIS_TEST)
-
-#Run test, and redirect the log into the file of THIS_TEST.log under TMP_LOGS_DIR/THIS_TEST/
-def run_test_fun():
- log_file = agl_test_conf.get_log_file(THIS_TEST)
- cwd = WORK_DIR + THIS_TEST + "/resource/"
- with open(log_file,'w') as log_f:
- subprocess.run(['sh','rpm_test.sh'],cwd=cwd,stdout=log_f,stderr=log_f)
- log_f.close()
@pytest.mark.oss_default
-def test_rpm01():
- global test_cases_values_and_status
- assert test_cases_values_and_status[1][1] == "TEST-PASS"
- test_cases_values_and_status[1][2] = "passed"
+def test_rpm01(testbase: RPMBase):
+ name = "rpm01"
+ testbase.run_case(name)
@pytest.mark.oss_default
-def test_rpm02():
- global test_cases_values_and_status
- assert test_cases_values_and_status[2][1] == "TEST-PASS"
- test_cases_values_and_status[2][2] = "passed"
+def test_rpm02(testbase: RPMBase):
+ name = "rpm02"
+ testbase.run_case(name)
@pytest.mark.oss_default
-def test_rpm03():
- global test_cases_values_and_status
- assert test_cases_values_and_status[3][1] == "TEST-PASS"
- test_cases_values_and_status[3][2] = "passed"
-
-#Pack the log file and count the test results
-def teardown_module():
- report.log_report(test_cases_values_and_status,THIS_TEST)
+def test_rpm03(testbase: RPMBase):
+ name = "rpm03"
+ testbase.run_case(name)
if __name__ == '__main__':
pytest.main("-s run_tests")