Commit 673f9c72 authored by lukas leufen's avatar lukas leufen

refac conftest

parent ef577861
Pipeline #39349 passed with stages
in 7 minutes and 30 seconds
......@@ -16,21 +16,26 @@ def pytest_runtest_teardown(item, nextitem):
path = os.path.dirname(__file__)
for stage in filter(None, rel_path.replace("..", ".").split("/")):
path = os.path.abspath(os.path.join(path, stage))
list_dir = os.listdir(path)
if "data" in list_dir and path != os.path.dirname(__file__): # do not delete data folder in src
shutil.rmtree(os.path.join(path, "data"), ignore_errors=True)
if "TestExperiment" in list_dir:
shutil.rmtree(os.path.join(path, "TestExperiment"), ignore_errors=True)
# remove all tracking json
remove_files_from_regex(list_dir, path, re.compile(r"tracking_\d*\.json"))
# remove all tracking pdf
remove_files_from_regex(list_dir, path, re.compile(r"tracking\.pdf"))
# remove all tracking json
remove_files_from_regex(list_dir, path, re.compile(r"logging_\d*\.log"))
execute_removing(path)
execute_removing(os.path.dirname(__file__))
else:
pass # nothing to do if next test is from same test class
def execute_removing(path):
list_dir = os.listdir(path)
if "data" in list_dir and path != os.path.dirname(__file__): # do not delete data folder in src
shutil.rmtree(os.path.join(path, "data"), ignore_errors=True)
# remove TestExperiment folders
remove_files_from_regex(list_dir, path, re.compile(r"TestExperiment_.*"))
# remove all tracking json
remove_files_from_regex(list_dir, path, re.compile(r"tracking_\d*\.json"))
# remove all tracking pdf
remove_files_from_regex(list_dir, path, re.compile(r"tracking_\d*\.pdf"))
# remove all tracking json
remove_files_from_regex(list_dir, path, re.compile(r"logging_\d*\.log"))
def remove_files_from_regex(list_dir, path, regex):
r = list(filter(regex.search, list_dir))
if len(r) > 0:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment