import os
import re
import time
+
+from preload.model import create_preloads
+from config import get_generator_plugin_names
+from tests.helpers import get_output_dir
+
try:
from html import escape
except ImportError:
ALL_RESULTS = []
-def get_output_dir(config):
- """
- Retrieve the output directory for the reports and create it if necessary
- :param config: pytest configuration
- :return: output directory as string
- """
- output_dir = config.option.output_dir or DEFAULT_OUTPUT_DIR
- if not os.path.exists(output_dir):
- os.makedirs(output_dir, exist_ok=True)
- return output_dir
-
-
def extract_error_msg(rep):
"""
If a custom error message was provided, then extract it otherwise
)
+def pytest_terminal_summary(terminalreporter, exitstatus):
+ # Ensures all preload information and warnings appear after
+ # test results
+ create_preloads(terminalreporter.config, exitstatus)
+
+
# noinspection PyUnusedLocal
def pytest_collection_modifyitems(session, config, items):
"""
{
"file_links": make_href(failure.files, template_path),
"test_id": failure.test_id,
- "error_message": escape(failure.error_message).replace("\n",
- "<br/><br/>"),
+ "error_message": escape(failure.error_message).replace(
+ "\n", "<br/><br/>"
+ ),
"raw_output": escape(failure.raw_output),
"requirements": docutils.core.publish_parts(
writer_name="html", source=failure.requirement_text(reqs)
help="optional category of test to execute",
)
+ parser.addoption(
+ "--env-directory",
+ dest="env_dir",
+ action="store",
+ help="optional directory of .env files for preload generation",
+ )
+
+ parser.addoption(
+ "--preload-format",
+ dest="preload_formats",
+ action="append",
+ help=(
+ "Preload format to create (multiple allowed). If not provided "
+ "then all available formats will be created: {}"
+ ).format(", ".join(get_generator_plugin_names())),
+ )
+
def pytest_configure(config):
"""
:param path: string directory containing files
:return: string MD5 hash code (hex)
"""
- md5 = hashlib.md5()
+ md5 = hashlib.md5() # nosec
for dir_path, sub_dirs, filenames in os.walk(path):
for filename in filenames:
file_path = os.path.join(dir_path, filename)
rst_path = os.path.join(output_dir, "rst.csv")
with open(rst_path, "w", newline="") as f:
out = csv.writer(f)
- out.writerow(("Requirement ID", "Requirement", "Test Module", "Test Name"))
+ out.writerow(("Requirement ID", "Test Module", "Test Name"))
for req_id, metadata in data.items():
out.writerow(
(
metadata["full_title"],
- metadata["description"],
metadata["test_case"],
metadata["validated_by"],
)