X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ice_validator%2Ftests%2Fconftest.py;h=54015d0dd03653a722cdf9a35b376f83b77af21c;hb=c1784fdec1f6bb4ebc103044293ab8a4f77361ab;hp=f5f25a33c46e10b5bc3055332e3e1f21766062e3;hpb=8de26dd1cc9ed33c3ab85a5014ac949f174db932;p=vvp%2Fvalidation-scripts.git
diff --git a/ice_validator/tests/conftest.py b/ice_validator/tests/conftest.py
index f5f25a3..54015d0 100644
--- a/ice_validator/tests/conftest.py
+++ b/ice_validator/tests/conftest.py
@@ -45,8 +45,11 @@ import os
import sys
import time
import requests
+import traceback
+import warnings
import docutils.core
+import jinja2
import pytest
from more_itertools import partition
from six import string_types
@@ -55,9 +58,7 @@ import xlsxwriter
__path__ = [os.path.dirname(os.path.abspath(__file__))]
resolution_steps_file = "resolution_steps.json"
-requirements_file = "requirements.json"
-
-FAILURE_DATA = {}
+heat_requirements_file = "heat_requirements.json"
report_columns = [
("Input File", "file"),
@@ -69,6 +70,12 @@ report_columns = [
]
report = collections.OrderedDict(report_columns)
+COLLECTION_FAILURES = []
+COLLECTION_FAILURE_WARNING = """WARNING: The following unexpected errors occurred
+while preparing to validate the the input files. Some validations may not have been
+executed. Please refer these issue to the VNF Validation Tool team.
+"""
+
def extract_error_msg(rep):
try:
@@ -92,6 +99,11 @@ def pytest_runtest_makereport(item, call):
if rep.outcome == "failed":
if not os.path.exists(output_dir):
os.mkdir(output_dir)
+ if os.path.exists("{}/failures".format(output_dir)):
+ with open("{}/failures".format(output_dir), "r") as o:
+ jdata = json.loads(o.read())
+ else:
+ jdata = {}
if hasattr(item.function, "requirement_ids"):
requirement_ids = item.function.requirement_ids
@@ -113,17 +125,31 @@ def pytest_runtest_makereport(item, call):
else:
resolved_pair = rep.nodeid.split("[")[1][:-1]
- FAILURE_DATA[len(FAILURE_DATA)] = {
+ markers = set(m.name for m in item.iter_markers())
+ base_test = "base" in markers
+
+ msg = extract_error_msg(rep)
+ if base_test:
+ msg = "!!Base Test Failure!! Halting test suite execution...\n{}".format(
+ msg
+ )
+
+ jdata[len(jdata)] = {
"file": resolved_pair,
"vnfrqts": requirement_ids,
"test": item.function.__name__,
"test_file": item.function.__module__.split(".")[-1],
"raw_output": str(rep.longrepr),
- "message": extract_error_msg(rep),
+ "message": msg,
}
with open("{}/failures".format(output_dir), "w") as f:
- json.dump(FAILURE_DATA, f, indent=4)
+ json.dump(jdata, f, indent=4)
+
+ if not item.config.option.continue_on_failure and base_test:
+ pytest.exit(
+ "{}\n{}\n{}".format(msg, resolved_pair, item.function.__name__)
+ )
def make_timestamp():
@@ -144,13 +170,31 @@ 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 and "xfail" not in markers:
- pytest.skip("No validation profile selected. Skipping tests with marks.")
- if profile and markers and profile not in markers and "xfail" not in markers:
- pytest.skip("Doesn't match selection validation profile")
+def pytest_collection_modifyitems(session, config, items):
+ allowed_marks = ["xfail", "base"]
+ profile = config.option.validation_profile
+
+ for item in items:
+ markers = set(m.name for m in item.iter_markers())
+ if not profile and markers and set(markers).isdisjoint(allowed_marks):
+ item.add_marker(
+ pytest.mark.skip(
+ reason="No validation profile selected. Skipping tests with marks."
+ )
+ )
+ if (
+ profile
+ and markers
+ and profile not in markers
+ and set(markers).isdisjoint(allowed_marks)
+ ):
+ item.add_marker(
+ pytest.mark.skip(reason="Doesn't match selection validation profile")
+ )
+
+ items.sort(
+ key=lambda item: 0 if "base" in set(m.name for m in item.iter_markers()) else 1
+ )
def make_href(path):
@@ -158,10 +202,10 @@ def make_href(path):
links = []
for p in paths:
abs_path = os.path.abspath(p)
- filename = os.path.split(abs_path)[1]
+ name = abs_path if os.path.isdir(abs_path) else os.path.split(abs_path)[1]
links.append(
- "{filename}".format(
- abs_path=abs_path, filename=filename
+ "{name}".format(
+ abs_path=abs_path, name=name
)
)
return "
".join(links)
@@ -184,7 +228,7 @@ def generate_report(outpath, template_path, profile_name, output_format):
with open(resolution_steps, "r") as f:
rdata = json.loads(f.read())
- heat_requirements = "{}/../{}".format(__path__[0], requirements_file)
+ heat_requirements = "{}/../{}".format(__path__[0], heat_requirements_file)
if os.path.exists(heat_requirements):
with open(heat_requirements, "r") as f:
hdata = json.loads(f.read())
@@ -203,6 +247,7 @@ def generate_report(outpath, template_path, profile_name, output_format):
# mapping resolution steps to module and test name
for k, v in faildata.items():
+ # resolution_step = ""
faildata[k]["resolution_steps"] = ""
for rs in rdata:
if v["test_file"] == rs["module"] and v["test"] == rs["function"]:
@@ -221,21 +266,33 @@ def generate_report(outpath, template_path, profile_name, output_format):
def generate_csv_report(output_dir, profile_name, template_path, faildata):
- rows = []
- rows.append(["Validation Failures"])
+ rows = [["Validation Failures"]]
headers = [
("Profile Selected:", profile_name),
("Report Generated At:", make_timestamp()),
("Directory Validated:", template_path),
("Checksum:", hash_directory(template_path)),
- ("Total Errors:", len(faildata)),
+ ("Total Errors:", len(faildata) + len(COLLECTION_FAILURES)),
]
-
rows.append([])
for header in headers:
rows.append(header)
rows.append([])
+ if COLLECTION_FAILURES:
+ rows.append([COLLECTION_FAILURE_WARNING])
+ rows.append(["Validation File", "Test", "Fixtures", "Error"])
+ for failure in COLLECTION_FAILURES:
+ rows.append(
+ [
+ failure["module"],
+ failure["test"],
+ ";".join(failure["fixtures"]),
+ failure["error"],
+ ]
+ )
+ rows.append([])
+
# table header
rows.append([col for col, _ in report_columns])
@@ -274,7 +331,7 @@ def generate_excel_report(output_dir, profile_name, template_path, faildata):
("Report Generated At:", make_timestamp()),
("Directory Validated:", template_path),
("Checksum:", hash_directory(template_path)),
- ("Total Errors:", len(faildata)),
+ ("Total Errors:", len(faildata) + len(COLLECTION_FAILURES)),
]
for row, (header, value) in enumerate(headers, start=2):
worksheet.write(row, 0, header, bold)
@@ -283,13 +340,26 @@ def generate_excel_report(output_dir, profile_name, template_path, faildata):
worksheet.set_column(0, len(headers) - 1, 40)
worksheet.set_column(len(headers), len(headers), 80)
+ if COLLECTION_FAILURES:
+ collection_failures_start = 2 + len(headers) + 2
+ worksheet.write(collection_failures_start, 0, COLLECTION_FAILURE_WARNING, bold)
+ collection_failure_headers = ["Validation File", "Test", "Fixtures", "Error"]
+ for col_num, col_name in enumerate(collection_failure_headers):
+ worksheet.write(collection_failures_start + 1, col_num, col_name, bold)
+ for row, data in enumerate(COLLECTION_FAILURES, collection_failures_start + 2):
+ worksheet.write(row, 0, data["module"])
+ worksheet.write(row, 1, data["test"])
+ worksheet.write(row, 2, ",".join(data["fixtures"]))
+ worksheet.write(row, 3, data["error"], code)
+
# table header
- start_error_table_row = 2 + len(headers) + 2
+ start_error_table_row = 2 + len(headers) + len(COLLECTION_FAILURES) + 4
+ worksheet.write(start_error_table_row, 0, "Validation Failures", bold)
for col_num, (col_name, _) in enumerate(report_columns):
- worksheet.write(start_error_table_row, col_num, col_name, bold)
+ worksheet.write(start_error_table_row + 1, col_num, col_name, bold)
# table content
- for row, data in enumerate(faildata.values(), start=start_error_table_row + 1):
+ for row, data in enumerate(faildata.values(), start=start_error_table_row + 2):
for col, key in enumerate(report.values()):
if key == "file":
paths = (
@@ -306,70 +376,35 @@ def generate_excel_report(output_dir, profile_name, template_path, faildata):
def generate_html_report(outpath, profile_name, template_path, faildata):
- with open("{}/report.html".format(outpath), "w") as of:
- body_begin = """
-
-
Success! No validation failures detected.
") - return - - table_begin = '{} | '.format(k)) - of.write("
---|
{} | ".format(value)) - of.write("