2023-07-10 15:55:10 +00:00
|
|
|
import logging
|
|
|
|
import re
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
import configs
|
|
|
|
from scripts.utils.system_path import SystemPath
|
|
|
|
|
2023-12-01 13:58:22 +00:00
|
|
|
LOG = logging.getLogger(__name__)
|
2023-07-10 15:55:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def generate_test_data(request):
|
|
|
|
test_path, test_name, test_params = generate_test_info(request.node)
|
|
|
|
configs.testpath.TEST = configs.testpath.RUN / test_path / test_name
|
2023-08-04 18:27:03 +00:00
|
|
|
node_dir = configs.testpath.TEST / test_params
|
|
|
|
configs.testpath.TEST_ARTIFACTS = node_dir / 'artifacts'
|
|
|
|
configs.testpath.TEST_VP = configs.testpath.VP / test_path / test_name
|
2023-12-01 13:58:22 +00:00
|
|
|
LOG.debug('Artifacts directory: %s',
|
2023-11-30 13:07:26 +00:00
|
|
|
configs.testpath.TEST_ARTIFACTS.relative_to(configs.testpath.ROOT))
|
2023-12-01 13:58:22 +00:00
|
|
|
LOG.debug('Verification points directory: %s',
|
2023-11-30 13:07:26 +00:00
|
|
|
configs.testpath.TEST_VP.relative_to(configs.testpath.ROOT))
|
2023-12-04 18:16:52 +00:00
|
|
|
LOG.info('Start test: %s', test_name)
|
2023-07-10 15:55:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
def generate_test_info(node):
|
|
|
|
pure_path = SystemPath(node.location[0]).parts[1:]
|
|
|
|
test_path = SystemPath(*pure_path).with_suffix('')
|
|
|
|
test_name = node.originalname
|
|
|
|
test_params = re.sub('[^a-zA-Z0-9\n\-_]', '', node.name.strip(test_name))
|
|
|
|
return test_path, test_name, test_params
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='session')
|
2023-08-04 18:27:03 +00:00
|
|
|
def prepare_test_directory():
|
2023-07-10 15:55:10 +00:00
|
|
|
keep_results = 5
|
|
|
|
run_name_pattern = 'run_????????_??????'
|
|
|
|
runs = list(sorted(configs.testpath.RESULTS.glob(run_name_pattern)))
|
|
|
|
if len(runs) > keep_results:
|
|
|
|
del_runs = runs[:len(runs) - keep_results]
|
|
|
|
for run in del_runs:
|
|
|
|
SystemPath(run).rmtree(ignore_errors=True)
|
2023-12-01 13:58:22 +00:00
|
|
|
LOG.info(f"Remove old test run directory: {run.relative_to(configs.testpath.ROOT)}")
|
2023-07-10 15:55:10 +00:00
|
|
|
configs.testpath.RUN.mkdir(parents=True, exist_ok=True)
|
2023-12-01 13:58:22 +00:00
|
|
|
LOG.info(f"Created new test run directory: {configs.testpath.RUN.relative_to(configs.testpath.ROOT)}")
|