VVP - Fixing script for traceability csv
[vvp/validation-scripts.git] / ice_validator / tests / conftest.py
index 09baa9a..f5f25a3 100644 (file)
@@ -44,6 +44,7 @@ import json
 import os
 import sys
 import time
+import requests
 
 import docutils.core
 import pytest
@@ -70,7 +71,11 @@ report = collections.OrderedDict(report_columns)
 
 
 def extract_error_msg(rep):
-    msg = str(rep.longrepr.reprcrash)
+    try:
+        msg = str(rep.longrepr.reprcrash)
+    except AttributeError:
+        msg = str(rep)
+
     if "AssertionError:" in msg:
         return msg.split("AssertionError:")[1]
     else:
@@ -142,9 +147,9 @@ def pytest_sessionfinish(session, exitstatus):
 def pytest_runtest_setup(item):
     profile = item.session.config.option.validation_profile
     markers = set(m.name for m in item.iter_markers())
-    if not profile and markers:
+    if not profile and markers and "xfail" not in markers:
         pytest.skip("No validation profile selected. Skipping tests with marks.")
-    if profile and markers and profile not in markers:
+    if profile and markers and profile not in markers and "xfail" not in markers:
         pytest.skip("Doesn't match selection validation profile")
 
 
@@ -528,6 +533,11 @@ def hash_directory(path):
 
 def load_current_requirements():
     """Loads dict of current requirements or empty dict if file doesn't exist"""
+
+    url = 'https://onap.readthedocs.io/en/latest/_downloads/needs.json'
+    r = requests.get(url)
+    with open('requirements.json', 'wb') as needs:
+        needs.write(r.content)
     path = "requirements.json"
     if not os.path.exists(path):
         return {}
@@ -566,7 +576,8 @@ def pytest_report_collectionfinish(config, startdir, items):
     mapping_errors = set()
     for item in mapped:
         for req_id in item.function.requirement_ids:
-            req_to_test[req_id].add(item)
+            if req_id not in req_to_test:
+                req_to_test[req_id].add(item)
             if req_id not in requirements:
                 mapping_errors.add(
                     (req_id, item.function.__module__, item.function.__name__)