From e0371eee986998087c4e75acb48039dcec2c6283 Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 31 Mar 2023 09:22:11 +0800 Subject: agl-test-framework: add LOG_MODE options add new options: "default", "slim", "clear". users can use export LOG_MODE="" to control how the framework would delete all its temp files or folders. "default": no influence, nothing would be removed. "slim": test self-owned temp files and folders removed. "clear": clean up each and every temp files and folders. Bug-AGL: SPEC-4733 Signed-off-by: Yan Change-Id: Ia3d8c2a971bbf97749448f732e848d9d15193459 --- plugins/agl_test_base.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'plugins/agl_test_base.py') diff --git a/plugins/agl_test_base.py b/plugins/agl_test_base.py index b30f841..1491f64 100644 --- a/plugins/agl_test_base.py +++ b/plugins/agl_test_base.py @@ -1,6 +1,8 @@ import pytest import os import json +import pathlib +import shutil import plugins.agl_test_utils as utils import plugins.agl_test_conf as conf @@ -111,6 +113,9 @@ class AGLBaseTest: #Write json data to html report.change_json_to_html(self.name) + #Clean temp files and folders + self.clean_self_tmp() + def precheck(self): return True; @@ -133,3 +138,23 @@ class AGLBaseTest: test_suites[self.name] = test_info json.dump(test_suites,f) f.close() + + def prepare_local_log_mode(self): + # Get env 'LOG_MODE' + env_dist=os.environ + local_log_mode = str(env_dist.get("LOG_MODE")) + return local_log_mode + + def clean_self_tmp(self): + path = self.get_temp_logdir() + log_mode = self.prepare_local_log_mode() + if log_mode == "slim" or log_mode == "clear": + # leave /log and report.json as essential + folderObj = pathlib.Path(path) + for element in folderObj.iterdir(): + if element.name != "log" and element.name != "report.json": + # check delete_file_path file type + if element.is_file(): + element.unlink() + elif element.is_dir(): + shutil.rmtree(path) -- cgit 1.2.3-korg