Skip to content

Commit 7d4c6b4

Browse files
committed
Update
[ghstack-poisoned]
1 parent 7f4fe99 commit 7d4c6b4

File tree

3 files changed

+51
-17
lines changed

3 files changed

+51
-17
lines changed

.ci/scripts/test_backend.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ if [[ $IS_MACOS -eq 1 ]]; then
6363
else
6464
SETUP_SCRIPT=.ci/scripts/setup-linux.sh
6565
fi
66-
${CONDA_PREFIX} CMAKE_ARGS="$EXTRA_BUILD_ARGS" $SETUP_SCRIPT --build-tool cmake --build-mode Release --editable true
66+
CMAKE_ARGS="$EXTRA_BUILD_ARGS" ${CONDA_PREFIX} $SETUP_SCRIPT --build-tool cmake --build-mode Release --editable true
6767

6868
EXIT_CODE=0
6969
${CONDA_PREFIX} pytest -c /dev/nul -n auto backends/test/suite/$SUITE/ -m flow_$FLOW --json-report --json-report-file="$REPORT_FILE" || EXIT_CODE=$?

backends/test/suite/conftest.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def test_runner(request):
8484

8585
@pytest.hookimpl(optionalhook=True)
8686
def pytest_json_runtest_metadata(item, call):
87+
# Store detailed results in the test report under the metadata key.
8788
metadata = {"subtests": []}
8889

8990
if hasattr(item, "funcargs") and "test_runner" in item.funcargs:
@@ -143,5 +144,39 @@ def pytest_json_runtest_metadata(item, call):
143144
)
144145

145146
metadata["subtests"].append(subtest_metadata)
146-
147147
return metadata
148+
149+
150+
@pytest.hookimpl(optionalhook=True)
151+
def pytest_json_modifyreport(json_report):
152+
# Post-process the report, mainly to populate metadata for crashed tests. The runtest_metadata
153+
# hook doesn't seem to be called when there's a native crash, but xdist still creates a report
154+
# entry.
155+
156+
for test_data in json_report["tests"]:
157+
if "metadata" not in test_data:
158+
test_data["metadata"] = {}
159+
metadata = test_data["metadata"]
160+
if "subtests" not in metadata:
161+
metadata["subtests"] = []
162+
subtests = metadata["subtests"]
163+
164+
# Native crashes are recorded differently and won't have the full metadata.
165+
# Pytest-xdist records crash info under the "???" key.
166+
if "???" in test_data:
167+
test_id = test_data["nodeid"].strip("::") # Remove leading ::
168+
test_base_id = test_id.split("[")[
169+
0
170+
] # Strip parameterization to get the base test case
171+
params = test_id[len(test_base_id) + 1 : -1].split("-")
172+
flow = params[0]
173+
174+
crashed_test_meta = {
175+
"Test ID": test_id,
176+
"Test Case": test_base_id,
177+
"Flow": flow,
178+
"Result": "Fail",
179+
"Result Detail": "Process Crash",
180+
"Error": test_data["???"].get("longrepr", "Process crashed."),
181+
}
182+
subtests.append(crashed_test_meta)

backends/test/suite/generate_markdown_summary_json.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,24 @@ def aggregate_results(json_path: str) -> AggregatedSummary:
7070
counts_by_param = {}
7171

7272
for test_data in data["tests"]:
73-
result_meta = test_data.get("metadata")
74-
if result_meta:
75-
for subtest_meta in result_meta["subtests"]:
76-
result = subtest_meta["Result"]
77-
result_detail = subtest_meta.get("Result Detail") or ""
73+
result_meta = test_data["metadata"]
74+
for subtest_meta in result_meta["subtests"]:
75+
result = subtest_meta["Result"]
76+
result_detail = subtest_meta.get("Result Detail") or ""
7877

79-
counts.add_row(result, result_detail)
78+
counts.add_row(result, result_detail)
8079

81-
test_id = subtest_meta["Test ID"]
82-
base_test = subtest_meta["Test Case"]
83-
params = test_id[len(base_test) + 1 : -1]
80+
test_id = subtest_meta["Test ID"]
81+
base_test = subtest_meta["Test Case"]
82+
params = test_id[len(base_test) + 1 : -1]
8483

85-
if params:
86-
if params not in counts_by_param:
87-
counts_by_param[params] = ResultCounts()
88-
counts_by_param[params].add_row(result, result_detail)
84+
if params:
85+
if params not in counts_by_param:
86+
counts_by_param[params] = ResultCounts()
87+
counts_by_param[params].add_row(result, result_detail)
8988

90-
if result.lower() == "fail":
91-
failed_tests.append(subtest_meta)
89+
if result.lower() == "fail":
90+
failed_tests.append(subtest_meta)
9291

9392
return AggregatedSummary(
9493
counts=counts,

0 commit comments

Comments
 (0)