Skip to content

Commit

Permalink
Add back JUnit reporting stats
Browse files Browse the repository at this point in the history
- Switch to using pytest-django to run the Django tests, as that has JUnit support. Add Django settings as a flag rather than in pyproject.toml because defining it there makes the normal pytest run fail since it can't find the module.
- Adds a simple script using junitparser to combine the two JUnit XML files.
  • Loading branch information
ColeDCrawford committed May 23, 2024
1 parent f262199 commit 5d3d80c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ jobs:

- name: Run unit tests
run: |
pytest
pytest --junitxml=junit_pytest_main.xml
mv .coverage .coverage_main
- name: Run Django integration tests
working-directory: ./edtf_django_tests
run: |
coverage run manage.py test edtf_integration
pytest edtf_integration/tests.py --ds=edtf_django_tests.settings --junitxml=../junit_pytest_django.xml
mv .coverage ../.coverage_django
- name: Combine coverage reports
Expand All @@ -59,16 +59,29 @@ jobs:
coverage report --omit="edtf_django_tests/*"
coverage xml -o coverage_combined.xml --omit="edtf_django_tests/*"
- name: Combine JUnit XML reports
run: |
python combine_junit.py combined_junit_pytest.xml junit_pytest_main.xml junit_pytest_django.xml
- name: Pytest coverage comment
id: coverageComment
uses: MishaKav/pytest-coverage-comment@main
with:
pytest-xml-coverage-path: ./coverage_combined.xml
junitxml-path: ./combined_junit_pytest.xml
unique-id-for-comment: ${{ matrix.python-version }}
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Check the output coverage
run: |
echo "Coverage Percentage - ${{ steps.coverageComment.outputs.coverage }}"
echo "Coverage Color - ${{ steps.coverageComment.outputs.color }}"
echo "Coverage Html - ${{ steps.coverageComment.outputs.coverageHtml }}"
echo "Summary Report - ${{ steps.coverageComment.outputs.summaryReport }}"
echo "Coverage Warnings - ${{ steps.coverageComment.outputs.warnings }}"
echo "Coverage Errors - ${{ steps.coverageComment.outputs.errors }}"
echo "Coverage Failures - ${{ steps.coverageComment.outputs.failures }}"
echo "Coverage Skipped - ${{ steps.coverageComment.outputs.skipped }}"
echo "Coverage Tests - ${{ steps.coverageComment.outputs.tests }}"
echo "Coverage Time - ${{ steps.coverageComment.outputs.time }}"
echo "Not Success Test Info - ${{ steps.coverageComment.outputs.notSuccessTestInfo }}"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ coverage_combined.xml
.coverage_main
.coverage_django
*,cover
combined_junit_pytest.xml
pytest.xml
junit_pytest_main.xml
junit_pytest_django.xml

# Translations
*.mo
Expand Down
23 changes: 23 additions & 0 deletions combine_junit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import sys

from junitparser import JUnitXml


def combine_junit_xml(output_file, *input_files):
combined_xml = JUnitXml()
for input_file in input_files:
xml = JUnitXml.fromfile(input_file)
combined_xml.extend(xml)
combined_xml.write(output_file)


if __name__ == "__main__":
if len(sys.argv) < 3:
print(
"Usage: python combine_junit_xml.py <output_file> <input_file1> <input_file2> ... <input_fileN>"
)
sys.exit(1)

output_file = sys.argv[1]
input_files = sys.argv[2:]
combine_junit_xml(output_file, *input_files)
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ classifiers = [
test = [
"django>=4.2,<5.0",
"pytest",
"pytest-django",
"ruff",
"pre-commit",
"coverage",
"pytest-cov"
"pytest-cov",
"junitparser",
]

[project.urls]
Expand Down Expand Up @@ -79,7 +81,7 @@ legacy_tox_ini = """
python_files = ["tests.py", "test_*.py", "*_test.py", "*_tests.py"]
python_classes = ["Test*", "*Tests"]
python_functions = ["test_*"]
addopts = "--ignore=edtf_django_tests/ --cov=edtf --cov-report=xml"
addopts = "--ignore=edtf_django_tests/ --cov=edtf"
plugins = ["pytest_cov"]

[tool.coverage.run]
Expand Down

0 comments on commit 5d3d80c

Please sign in to comment.