Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds unit-test xml report generation task #212

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions nautobot-app/{{ cookiecutter.project_slug }}/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import os
import re
import sys
import xml.etree.ElementTree as ET
from pathlib import Path
from time import sleep

Expand Down Expand Up @@ -848,6 +849,26 @@ def unittest_coverage(context):
run_command(context, command)



@task(pre=[unittest])
def unittest_xml_coverage(context):
"""Produce an XML coverage report that can be ingested into other tools."""
produce_xml_cmd = "coverage xml --include '{{ cookiecutter.app_name }}/*'"
run_command(context, produce_xml_cmd)

# Since the container runs from a different working dir,
# We have to edit the XML to inject the current directory
# to play nice with tools outside of the container.
cur_dir = os.path.dirname(__file__)
cov_xml_path = os.path.join(cur_dir, "coverage.xml")

tree = ET.parse(cov_xml_path) # noqa: S314
root = tree.getroot()

root.find(".//sources/source").text = cur_dir
tree.write(cov_xml_path, encoding="utf-8", xml_declaration=True)


@task(
help={
"failfast": "fail as soon as a single test fails don't run the entire test suite. (default: False)",
Expand Down