Skip to content

Commit

Permalink
Adds unit-test xml report generation task
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Sheinberg committed Jan 10, 2025
1 parent ceac6b5 commit 497732b
Showing 1 changed file with 21 additions and 0 deletions.
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

0 comments on commit 497732b

Please sign in to comment.