From 4fb6366472129d58057aab2189d7b96420e99b27 Mon Sep 17 00:00:00 2001 From: Gwenael Lambrouin Date: Thu, 15 Jul 2021 11:33:21 +0200 Subject: behave_tests: create results dir if needed Change-Id: I122607f24844eda15920b514a29e4efba9a7c4e6 Signed-off-by: Gwenael Lambrouin --- behave_tests/features/environment.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/behave_tests/features/environment.py b/behave_tests/features/environment.py index 12cd4cc..bb9780d 100644 --- a/behave_tests/features/environment.py +++ b/behave_tests/features/environment.py @@ -17,6 +17,7 @@ import json import os +import pathlib import time @@ -59,8 +60,13 @@ def before_scenario(context, scenario): def after_feature(context, feature): - if context.results: - with open(os.path.join( - '/var/lib/xtesting/results/' + context.CASE_NAME + '/campaign_result.json'), "w") \ - as outfile: - json.dump(context.results, outfile) + if len(context.results) == 0: + # No result to dump + return + + results_dir = pathlib.Path('/var/lib/xtesting/results/' + context.CASE_NAME) + if not results_dir.exists(): + results_dir.mkdir() + + results_file = results_dir / pathlib.Path('campaign_result.json') + results_file.write_text(json.dumps(context.results, indent=4)) -- cgit 1.2.3-korg