Skip to content

Commit 8555c86

Browse files
[GHA] summary for test examples (#3079)
### 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)
1 parent 1744c3d commit 8555c86

File tree

2 files changed

+71
-8
lines changed

2 files changed

+71
-8
lines changed

Diff for: .github/scripts/pytest_md_summary.py

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright (c) 2024 Intel Corporation
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
# Unless required by applicable law or agreed to in writing, software
7+
# distributed under the License is distributed on an "AS IS" BASIS,
8+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
# See the License for the specific language governing permissions and
10+
# limitations under the License.
11+
12+
"""
13+
This script generates a summary table in Markdown format from an XML report generated by pytest.
14+
15+
Usage in GitHub workflow:
16+
- name: Test Summary
17+
if: ${{ !cancelled() }}
18+
run: |
19+
python .github/scripts/generate_examples_summary.py pytest-results.xml >> $GITHUB_STEP_SUMMARY
20+
"""
21+
22+
import sys
23+
import xml.etree.ElementTree as ET
24+
25+
# Load the XML report generated by pytest
26+
xml_file = sys.argv[1]
27+
28+
try:
29+
tree = ET.parse(xml_file)
30+
except FileNotFoundError:
31+
sys.exit(1)
32+
33+
root = tree.getroot()
34+
35+
# Build the summary table in Markdown format
36+
table_lines = []
37+
table_lines.append("| Test Name | Status | Time | Message |")
38+
table_lines.append("|:----------|:------:|-----:|:--------|")
39+
40+
# Iterate over test cases
41+
for testcase in root.findall(".//testcase"):
42+
test_name = testcase.get("name")
43+
time_duration = float(testcase.get("time", "0"))
44+
message = ""
45+
if testcase.find("failure") is not None:
46+
status = "$${\color{red}Failed}$$"
47+
message = testcase.find("failure").get("message", "")
48+
elif testcase.find("error") is not None:
49+
status = "$${\color{red}Error}$$"
50+
elif testcase.find("skipped") is not None:
51+
status = "$${\color{orange}Skipped}$$"
52+
message = testcase.find("skipped").get("message", "")
53+
else:
54+
status = "$${\color{green}Ok}$$"
55+
56+
# Append each row to the table
57+
table_lines.append(f"| {test_name} | {status} | {time_duration:.0f} | {message} |")
58+
59+
print("\n".join(table_lines))

Diff for: .github/workflows/examples.yml

+12-8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ on:
1313
description: 'Pytest arguments'
1414
default: ''
1515

16+
concurrency:
17+
group: test-examples-${{ github.workflow }}-${{ github.ref }}-${{ github.event.inputs.pytest_args || '' }}-${{github.event.inputs.pull_request_number || ''}}
18+
cancel-in-progress: false
19+
1620
jobs:
1721
examples-cpu:
1822
name: Test exmaples CPU [${{ matrix.group }}/4]
@@ -48,19 +52,19 @@ jobs:
4852
run: pip list
4953
- name: Run examples test scope
5054
run: |
51-
python -m pytest -ras tests/cross_fw/examples \
52-
--junit-xml=pytest-results-${{ matrix.group }}.xml \
55+
set +e
56+
python -m pytest -s -ra tests/cross_fw/examples \
57+
--junit-xml=pytest-results.xml \
5358
--durations-path=tests/cross_fw/examples/.test_durations \
5459
--splitting-algorithm=least_duration \
5560
--splits 4 \
5661
--group ${{ matrix.group }} \
5762
${{ github.event.inputs.pytest_args || '' }}
63+
ret=$?
64+
[ $ret -eq 5 ] && [ -n "${{ github.event.inputs.pytest_args || '' }}" ] && exit 0 || exit $ret
5865
env:
5966
TQDM_DISABLE: 1
60-
- name: Upload artifact
61-
uses: actions/upload-artifact@v4
67+
- name: Test Summary
6268
if: ${{ !cancelled() }}
63-
with:
64-
name: pytest-results-${{ matrix.group }}
65-
path: pytest-results-${{ matrix.group }}.xml
66-
overwrite: True
69+
run: |
70+
python .github/scripts/pytest_md_summary.py pytest-results.xml >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)