Skip to content

Commit

Permalink
[GHA] summary for test examples (#3079)
Browse files Browse the repository at this point in the history
### Changes

- Add summary for jobs 
- Fix pytest argumets `-ra -s`
- Dont fail job if run workflow manually for less 4 examples (catch
return code 5)


### Tests


[test_examples](https://github.com/openvinotoolkit/nncf/actions/runs/11798937213)
  • Loading branch information
AlexanderDokuchaev authored Nov 13, 2024
1 parent 1744c3d commit 8555c86
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 8 deletions.
59 changes: 59 additions & 0 deletions .github/scripts/pytest_md_summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright (c) 2024 Intel Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
This script generates a summary table in Markdown format from an XML report generated by pytest.
Usage in GitHub workflow:
- name: Test Summary
if: ${{ !cancelled() }}
run: |
python .github/scripts/generate_examples_summary.py pytest-results.xml >> $GITHUB_STEP_SUMMARY
"""

import sys
import xml.etree.ElementTree as ET

# Load the XML report generated by pytest
xml_file = sys.argv[1]

try:
tree = ET.parse(xml_file)
except FileNotFoundError:
sys.exit(1)

root = tree.getroot()

# Build the summary table in Markdown format
table_lines = []
table_lines.append("| Test Name | Status | Time | Message |")
table_lines.append("|:----------|:------:|-----:|:--------|")

# Iterate over test cases
for testcase in root.findall(".//testcase"):
test_name = testcase.get("name")
time_duration = float(testcase.get("time", "0"))
message = ""
if testcase.find("failure") is not None:
status = "$${\color{red}Failed}$$"
message = testcase.find("failure").get("message", "")
elif testcase.find("error") is not None:
status = "$${\color{red}Error}$$"
elif testcase.find("skipped") is not None:
status = "$${\color{orange}Skipped}$$"
message = testcase.find("skipped").get("message", "")
else:
status = "$${\color{green}Ok}$$"

# Append each row to the table
table_lines.append(f"| {test_name} | {status} | {time_duration:.0f} | {message} |")

print("\n".join(table_lines))
20 changes: 12 additions & 8 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ on:
description: 'Pytest arguments'
default: ''

concurrency:
group: test-examples-${{ github.workflow }}-${{ github.ref }}-${{ github.event.inputs.pytest_args || '' }}-${{github.event.inputs.pull_request_number || ''}}
cancel-in-progress: false

jobs:
examples-cpu:
name: Test exmaples CPU [${{ matrix.group }}/4]
Expand Down Expand Up @@ -48,19 +52,19 @@ jobs:
run: pip list
- name: Run examples test scope
run: |
python -m pytest -ras tests/cross_fw/examples \
--junit-xml=pytest-results-${{ matrix.group }}.xml \
set +e
python -m pytest -s -ra tests/cross_fw/examples \
--junit-xml=pytest-results.xml \
--durations-path=tests/cross_fw/examples/.test_durations \
--splitting-algorithm=least_duration \
--splits 4 \
--group ${{ matrix.group }} \
${{ github.event.inputs.pytest_args || '' }}
ret=$?
[ $ret -eq 5 ] && [ -n "${{ github.event.inputs.pytest_args || '' }}" ] && exit 0 || exit $ret
env:
TQDM_DISABLE: 1
- name: Upload artifact
uses: actions/upload-artifact@v4
- name: Test Summary
if: ${{ !cancelled() }}
with:
name: pytest-results-${{ matrix.group }}
path: pytest-results-${{ matrix.group }}.xml
overwrite: True
run: |
python .github/scripts/pytest_md_summary.py pytest-results.xml >> $GITHUB_STEP_SUMMARY

0 comments on commit 8555c86

Please sign in to comment.