Skip to content

Commit 7f25cec

Browse files
committed
Move reporting stuff to its own file, and add parametrize values to the report
1 parent ed4d58e commit 7f25cec

File tree

2 files changed

+61
-22
lines changed

2 files changed

+61
-22
lines changed

conftest.py

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
from pathlib import Path
33

44
from hypothesis import settings
5-
from pytest import mark, fixture
5+
from pytest import mark
66

77
from array_api_tests import _array_module as xp
88
from array_api_tests._array_module import _UndefinedStub
99

10-
settings.register_profile("xp_default", deadline=800)
10+
from reporting import pytest_metadata, add_api_name_to_metadata # noqa
1111

12+
settings.register_profile("xp_default", deadline=800)
1213

1314
def pytest_addoption(parser):
1415
# Hypothesis max examples
@@ -125,23 +126,3 @@ def pytest_collection_modifyitems(config, items):
125126
ci_mark = next((m for m in markers if m.name == "ci"), None)
126127
if ci_mark is None:
127128
item.add_marker(mark.skip(reason="disabled via --ci"))
128-
129-
@mark.optionalhook
130-
def pytest_metadata(metadata):
131-
"""
132-
Additional metadata for --json-report.
133-
"""
134-
metadata['array_api_tests_module'] = xp.mod_name
135-
136-
@fixture(autouse=True)
137-
def add_api_name_to_metadata(request, json_metadata):
138-
test_module = request.module.__name__
139-
test_function = request.function.__name__
140-
assert test_function.startswith('test_'), 'unexpected test function name'
141-
142-
if test_module == 'array_api_tests.test_has_names':
143-
array_api_function_name = None
144-
else:
145-
array_api_function_name = test_function[len('test_'):]
146-
147-
json_metadata['array_api_function_name'] = array_api_function_name

reporting.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from array_api_tests.test_operators_and_elementwise_functions import (UnaryParamContext, BinaryParamContext)
2+
from array_api_tests.dtype_helpers import dtype_to_name
3+
from array_api_tests import _array_module as xp
4+
5+
from pytest import mark, fixture
6+
7+
def to_json_serializable(o):
8+
if o in dtype_to_name:
9+
return dtype_to_name[o]
10+
if isinstance(o, UnaryParamContext):
11+
return {'func_name': o.func_name}
12+
if isinstance(o, BinaryParamContext):
13+
return {
14+
'func_name': o.func_name,
15+
'left_sym': o.left_sym,
16+
'right_sym': o.right_sym,
17+
'right_is_scalar': o.right_is_scalar,
18+
'res_name': o.res_name,
19+
}
20+
if isinstance(o, dict):
21+
return {to_json_serializable(k): to_json_serializable(v) for k, v in o.items()}
22+
if isinstance(o, tuple):
23+
return tuple(to_json_serializable(i) for i in o)
24+
if isinstance(o, list):
25+
return [to_json_serializable(i) for i in o]
26+
27+
return o
28+
29+
@mark.optionalhook
30+
def pytest_metadata(metadata):
31+
"""
32+
Additional global metadata for --json-report.
33+
"""
34+
metadata['array_api_tests_module'] = xp.mod_name
35+
36+
@fixture(autouse=True)
37+
def add_api_name_to_metadata(request, json_metadata):
38+
"""
39+
Additional per-test metadata for --json-report
40+
"""
41+
test_module = request.module.__name__
42+
if test_module.startswith('array_api_tests.meta'):
43+
return
44+
45+
test_function = request.function.__name__
46+
assert test_function.startswith('test_'), 'unexpected test function name'
47+
48+
if test_module == 'array_api_tests.test_has_names':
49+
array_api_function_name = None
50+
else:
51+
array_api_function_name = test_function[len('test_'):]
52+
53+
json_metadata['test_module'] = test_module
54+
json_metadata['test_function'] = test_function
55+
json_metadata['array_api_function_name'] = array_api_function_name
56+
57+
if hasattr(request.node, 'callspec'):
58+
json_metadata['params'] = to_json_serializable(request.node.callspec.params)

0 commit comments

Comments
 (0)