aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGwenael Lambrouin <gwenael.lambrouin@orange.com>2021-07-16 15:40:16 +0200
committerGwenael Lambrouin <gwenael.lambrouin@orange.com>2021-07-22 17:08:18 +0200
commit10655a8b254f7e19fee18892a49bc85f47e68d75 (patch)
tree628eb78688de6d56f05c61cda5c6f9be58287451
parent36f79f13aebbcd2848e07ec4c279a3daa13aafae (diff)
behave_tests: add secondary logging infrastructure
In addition to the main logger managed by behave framework to show the test progress and the results summary, add a second logger to provide insight on what's going on internally. That second logger logs to a file in the results dir. Change-Id: Ie2e8012ea54b153a2e661a06a2c521f48e7040b2 Signed-off-by: Gwenael Lambrouin <gwenael.lambrouin@orange.com>
-rw-r--r--behave_tests/features/environment.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/behave_tests/features/environment.py b/behave_tests/features/environment.py
index 7789ca8..61096f6 100644
--- a/behave_tests/features/environment.py
+++ b/behave_tests/features/environment.py
@@ -17,6 +17,7 @@
import json
import os
+import logging
import pathlib
import time
@@ -45,6 +46,22 @@ def before_feature(context, feature):
context.start_time = time.time()
context.CASE_NAME = feature.name
+ # Create results dir if needed
+ results_dir = pathlib.Path('/var/lib/xtesting/results/' + context.CASE_NAME)
+ if not results_dir.exists():
+ results_dir.mkdir()
+
+ # Setup a second logger to be able to understand why a test passed or failed
+ # (The main logger is used by behave itself)
+ context.logger = logging.getLogger('behave_tests')
+ context.logger.setLevel(logging.INFO)
+ fh = logging.FileHandler(filename=results_dir / pathlib.Path('behave_tests.log'),
+ mode='w') # Re-create the file at the beginning of the feature
+ fh.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
+ context.logger.addHandler(fh)
+
+ context.logger.info('before_feature: ' + feature.name)
+
def before_scenario(context, scenario):
context.tag = scenario.tags[0]
@@ -57,6 +74,8 @@ def before_scenario(context, scenario):
context.json['flavor_type'] = loopvm_flavor
context.synthesis = {}
+ context.logger.info('before_scenario: ' + scenario.name)
+
def after_feature(context, feature):
if len(context.results) == 0:
@@ -64,8 +83,5 @@ def after_feature(context, feature):
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))