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
msheiny committed Jan 9, 2025
1 parent ceac6b5 commit 97f64cc
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 @@ -848,6 +848,27 @@ 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 }}/*' --omit *migrations*"
run_command(context, produce_xml_cmd)

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

# I was originally going to use ET lib but linter throws a CVE warning
# https://docs.astral.sh/ruff/rules/suspicious-xml-element-tree-usage/
with open(cov_xml_path, "r+") as f:
contents = f.read()
updated_contents = contents.replace('>/source<', f">{cur_dir}<")
f.seek(0)
f.write(updated_contents)
f.truncate()


@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 97f64cc

Please sign in to comment.