Skip to content

Commit 0538820

Browse files
authored
[CI] Better reports #2 (huggingface#8163)
1 parent 9a21b50 commit 0538820

File tree

2 files changed

+64
-20
lines changed

2 files changed

+64
-20
lines changed

.github/workflows/self-scheduled.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ jobs:
6363
source .env/bin/activate
6464
python -m pytest -n 1 --dist=loadfile -s --make_reports=tests tests
6565
66+
- name: Failure short reports
67+
if: ${{ always() }}
68+
run: cat reports/report_tests_failures_short.txt
69+
6670
- name: Run examples tests on GPU
71+
if: ${{ always() }}
6772
env:
6873
TF_FORCE_GPU_ALLOW_GROWTH: "true"
6974
OMP_NUM_THREADS: 1
@@ -73,7 +78,12 @@ jobs:
7378
pip install -r examples/requirements.txt
7479
python -m pytest -n 1 --dist=loadfile -s --make_reports=examples examples
7580
81+
- name: Failure short reports
82+
if: ${{ always() }}
83+
run: cat reports/report_examples_failures_short.txt
84+
7685
- name: Run all pipeline tests on GPU
86+
if: ${{ always() }}
7787
env:
7888
TF_FORCE_GPU_ALLOW_GROWTH: "true"
7989
OMP_NUM_THREADS: 1
@@ -83,11 +93,15 @@ jobs:
8393
source .env/bin/activate
8494
python -m pytest -n 1 --dist=loadfile -s -m is_pipeline_test --make_reports=tests_pipeline tests
8595
86-
- name: test suite reports artifacts
96+
- name: Failure short reports
97+
if: ${{ always() }}
98+
run: cat reports/report_tests_pipeline_failures_short.txt
99+
100+
- name: Test suite reports artifacts
87101
if: ${{ always() }}
88102
uses: actions/upload-artifact@v2
89103
with:
90-
name: test_reports
104+
name: run_all_tests_torch_and_tf_gpu_test_reports
91105
path: reports
92106

93107

src/transformers/testing_utils.py

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -725,18 +725,22 @@ def pytest_terminal_summary_main(tr, id):
725725
orig_tbstyle = config.option.tbstyle
726726
orig_reportchars = tr.reportchars
727727

728-
report_files = dict(
729-
durations="durations",
730-
short_summary="short_summary",
731-
summary_errors="errors",
732-
summary_failures="failures",
733-
summary_warnings="warnings",
734-
summary_passes="passes",
735-
summary_stats="stats",
736-
)
737728
dir = "reports"
738729
Path(dir).mkdir(parents=True, exist_ok=True)
739-
report_files.update((k, f"{dir}/report_{id}_{v}.txt") for k, v in report_files.items())
730+
report_files = {
731+
k: f"{dir}/report_{id}_{k}.txt"
732+
for k in [
733+
"durations",
734+
"errors",
735+
"failures_long",
736+
"failures_short",
737+
"failures_line",
738+
"passes",
739+
"stats",
740+
"summary_short",
741+
"warnings",
742+
]
743+
}
740744

741745
# custom durations report
742746
# note: there is no need to call pytest --durations=XX to get this separate report
@@ -757,34 +761,60 @@ def pytest_terminal_summary_main(tr, id):
757761
break
758762
f.write(f"{rep.duration:02.2f}s {rep.when:<8} {rep.nodeid}\n")
759763

764+
def summary_failures_short(tr):
765+
# expecting that the reports were --tb=long (default) so we chop them off here to the last frame
766+
reports = tr.getreports("failed")
767+
if not reports:
768+
return
769+
tr.write_sep("=", "FAILURES SHORT STACK")
770+
for rep in reports:
771+
msg = tr._getfailureheadline(rep)
772+
tr.write_sep("_", msg, red=True, bold=True)
773+
# chop off the optional leading extra frames, leaving only the last one
774+
longrepr = re.sub(r".*_ _ _ (_ ){10,}_ _ ", "", rep.longreprtext, 0, re.M | re.S)
775+
tr._tw.line(longrepr)
776+
# note: not printing out any rep.sections to keep the report short
777+
760778
# use ready-made report funcs, we are just hijacking the filehandle to log to a dedicated file each
761779
# adapted from https://github.com/pytest-dev/pytest/blob/897f151e/src/_pytest/terminal.py#L814
762780
# note: some pytest plugins may interfere by hijacking the default `terminalreporter` (e.g.
763781
# pytest-instafail does that)
764-
tr.reportchars = "wPpsxXEf" # emulate -rA (used in summary_passes() and short_test_summary())
765-
config.option.tbstyle = "auto"
766-
with open(report_files["summary_failures"], "w") as f:
782+
783+
# report failures with line/short/long styles
784+
config.option.tbstyle = "auto" # full tb
785+
with open(report_files["failures_long"], "w") as f:
786+
tr._tw = create_terminal_writer(config, f)
787+
tr.summary_failures()
788+
789+
# config.option.tbstyle = "short" # short tb
790+
with open(report_files["failures_short"], "w") as f:
791+
tr._tw = create_terminal_writer(config, f)
792+
summary_failures_short(tr)
793+
794+
config.option.tbstyle = "line" # one line per error
795+
with open(report_files["failures_line"], "w") as f:
767796
tr._tw = create_terminal_writer(config, f)
768797
tr.summary_failures()
769798

770-
with open(report_files["summary_errors"], "w") as f:
799+
with open(report_files["errors"], "w") as f:
771800
tr._tw = create_terminal_writer(config, f)
772801
tr.summary_errors()
773802

774-
with open(report_files["summary_warnings"], "w") as f:
803+
with open(report_files["warnings"], "w") as f:
775804
tr._tw = create_terminal_writer(config, f)
776805
tr.summary_warnings() # normal warnings
777806
tr.summary_warnings() # final warnings
778807

779-
with open(report_files["summary_passes"], "w") as f:
808+
tr.reportchars = "wPpsxXEf" # emulate -rA (used in summary_passes() and short_test_summary())
809+
with open(report_files["passes"], "w") as f:
780810
tr._tw = create_terminal_writer(config, f)
781811
tr.summary_passes()
782812

783-
with open(report_files["short_summary"], "w") as f:
813+
with open(report_files["summary_short"], "w") as f:
784814
tr._tw = create_terminal_writer(config, f)
785815
tr.short_test_summary()
786816

787-
with open(report_files["summary_stats"], "w") as f:
817+
with open(report_files["stats"], "w") as f:
788818
tr._tw = create_terminal_writer(config, f)
789819
tr.summary_stats()
790820

0 commit comments

Comments
 (0)