Skip to content

Commit 0841ef3

Browse files
committed
De-duplicate warnings metadata in the report JSON
This was causing the report file sizes to be huge, especially for plain numpy.
1 parent a1ccd19 commit 0841ef3

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from array_api_tests import _array_module as xp
88
from array_api_tests._array_module import _UndefinedStub
99

10-
from reporting import pytest_metadata, add_extra_json_metadata # noqa
10+
from reporting import pytest_metadata, pytest_json_modifyreport, add_extra_json_metadata # noqa
1111

1212
settings.register_profile("xp_default", deadline=800)
1313

reporting.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from array_api_tests import _array_module as xp
33
from array_api_tests import __version__
44

5+
from collections import Counter
56
from types import BuiltinFunctionType, FunctionType
67
import dataclasses
78
import json
@@ -89,3 +90,19 @@ def finalizer():
8990
add_metadata('hypothesis_statistics', request.node.hypothesis_statistics)
9091

9192
request.addfinalizer(finalizer)
93+
94+
def pytest_json_modifyreport(json_report):
95+
# Deduplicate warnings. These duplicate warnings can cause the file size
96+
# to become huge. For instance, a warning from np.bool which is emitted
97+
# every time hypothesis runs (over a million times) causes the warnings
98+
# JSON for a plain numpy namespace run to be over 500MB.
99+
100+
# This will lose information about what order the warnings were issued in,
101+
# but that isn't particularly helpful anyway since the warning metadata
102+
# doesn't store a full stack of where it was issued from. The resulting
103+
# warnings will be in order of the first time each warning is issued since
104+
# collections.Counter is ordered just like dict().
105+
counted_warnings = Counter([frozenset(i.items()) for i in json_report['warnings']])
106+
deduped_warnings = [{**dict(i), 'count': counted_warnings[i]} for i in counted_warnings]
107+
108+
json_report['warnings'] = deduped_warnings

0 commit comments

Comments
 (0)