aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGwenael Lambrouin <gwenael.lambrouin@orange.com>2021-07-15 11:33:21 +0200
committerGwenael Lambrouin <gwenael.lambrouin@orange.com>2021-07-22 17:08:18 +0200
commit4fb6366472129d58057aab2189d7b96420e99b27 (patch)
treefe5dede9b443461df04facb669a3396935f70488
parent67c8e918e97c91be16de253a8f0bcaddf285524a (diff)
behave_tests: create results dir if needed
Change-Id: I122607f24844eda15920b514a29e4efba9a7c4e6 Signed-off-by: Gwenael Lambrouin <gwenael.lambrouin@orange.com>
-rw-r--r--behave_tests/features/environment.py16
1 files 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))