Skip to content

Commit 93e71cc

Browse files
ezyangpytorchmergebot
authored andcommitted
Add helpers for running tests and then putting them in a CSV (#92642)
Signed-off-by: Edward Z. Yang <ezyang@meta.com> Pull Request resolved: #92642 Approved by: https://github.com/albanD
1 parent 756acd3 commit 93e71cc

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""
2+
This script takes a pytest CSV file produced by pytest --csv foo.csv
3+
and summarizes it into a more minimal CSV that is good for uploading
4+
to Google Sheets. We have been using this with dynamic shapes to
5+
understand how many tests fail when we turn on dynamic shapes. If
6+
you have a test suite with a lot of skips or xfails, if force the
7+
tests to run anyway, this can help you understand what the actual
8+
errors things are failing with are.
9+
10+
The resulting csv is written to stdout. An easy way to get the csv
11+
onto your local file system is to send it to GitHub Gist:
12+
13+
$ python scripts/analysis/format_test_csv.py foo.csv | gh gist create -
14+
15+
See also scripts/analysis/run_test_csv.sh
16+
"""
17+
18+
import csv
19+
import subprocess
20+
import sys
21+
import argparse
22+
23+
parser = argparse.ArgumentParser(description=__doc__,
24+
formatter_class=argparse.RawDescriptionHelpFormatter)
25+
parser.add_argument("--log-url", type=str, default="", help="URL of raw logs")
26+
parser.add_argument("file", help="pytest CSV file to format")
27+
args = parser.parse_args()
28+
29+
out = csv.writer(sys.stdout, dialect="excel")
30+
hash = subprocess.check_output(
31+
"git rev-parse HEAD".split(" "), encoding="utf-8"
32+
).rstrip()
33+
34+
out.writerow([hash, args.log_url, ""])
35+
36+
with open(args.file, "r") as f:
37+
reader = csv.DictReader(f)
38+
for row in reader:
39+
if row["status"] not in {"failed", "error"}:
40+
continue
41+
msg = row["message"].split("\n")[0]
42+
msg.replace(
43+
" - erroring out! It's likely that this is caused by data-dependent control flow or similar.",
44+
"",
45+
)
46+
msg.replace("\t", " ")
47+
# Feel free to edit this; the idea is to remove prefixes that are
48+
# just gooping up the resulting spreadsheet outpu
49+
name = row["name"].replace("test_make_fx_symbolic_exhaustive_", "")
50+
out.writerow([name, msg, ""])

scripts/analysis/run_test_csv.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
# Typical usage:
4+
#
5+
# scripts/analysis/run_test_csv.sh test/inductor/test_torchinductor.py
6+
7+
set -x
8+
9+
if getent hosts fwdproxy; then
10+
export https_proxy=http://fwdproxy:8080 http_proxy=http://fwdproxy:8080 no_proxy=.fbcdn.net,.facebook.com,.thefacebook.com,.tfbnw.net,.fb.com,.fburl.com,.facebook.net,.sb.fbsbx.com,localhost
11+
fi
12+
TEST_FILE="$1"
13+
TEST_ARGS="$*" # includes file name
14+
shift
15+
pytest --csv "$TEST_FILE.csv" -v "$TEST_FILE" "$@" 2>&1 | tee "$TEST_FILE.log"
16+
LOG_URL="$(gh gist create -d "Test logs for $TEST_ARGS" "$TEST_FILE.log")"
17+
python "$(dirname "$BASH_SOURCE")"/format_test_csv.py --log-url "$LOG_URL" "$TEST_FILE.csv" | gh gist create -

0 commit comments

Comments
 (0)