1
1
from functools import lru_cache
2
2
from pathlib import Path
3
3
4
- from pytest import mark
5
4
from hypothesis import settings
5
+ from pytest import mark
6
6
7
7
from array_api_tests import _array_module as xp
8
8
from array_api_tests ._array_module import _UndefinedStub
9
9
10
-
11
- settings .register_profile ('xp_default' , deadline = 800 )
10
+ settings .register_profile ("xp_default" , deadline = 800 )
12
11
13
12
14
13
def pytest_addoption (parser ):
15
14
# Hypothesis max examples
16
15
# See https://github.com/HypothesisWorks/hypothesis/issues/2434
17
16
parser .addoption (
18
- ' --hypothesis-max-examples' ,
19
- ' --max-examples' ,
20
- action = ' store' ,
17
+ " --hypothesis-max-examples" ,
18
+ " --max-examples" ,
19
+ action = " store" ,
21
20
default = None ,
22
- help = ' set the Hypothesis max_examples setting' ,
21
+ help = " set the Hypothesis max_examples setting" ,
23
22
)
24
23
# Hypothesis deadline
25
24
parser .addoption (
26
- ' --hypothesis-disable-deadline' ,
27
- ' --disable-deadline' ,
28
- action = ' store_true' ,
29
- help = ' disable the Hypothesis deadline' ,
25
+ " --hypothesis-disable-deadline" ,
26
+ " --disable-deadline" ,
27
+ action = " store_true" ,
28
+ help = " disable the Hypothesis deadline" ,
30
29
)
31
30
# enable/disable extensions
32
31
parser .addoption (
33
- ' --enable-extension' ,
34
- metavar = ' ext' ,
35
- nargs = '+' ,
32
+ " --enable-extension" ,
33
+ metavar = " ext" ,
34
+ nargs = "+" ,
36
35
default = [],
37
- help = ' enable testing for Array API extension(s)' ,
36
+ help = " enable testing for Array API extension(s)" ,
38
37
)
39
38
parser .addoption (
40
- ' --disable-extension' ,
41
- metavar = ' ext' ,
42
- nargs = '+' ,
39
+ " --disable-extension" ,
40
+ metavar = " ext" ,
41
+ nargs = "+" ,
43
42
default = [],
44
- help = ' disable testing for Array API extension(s)' ,
43
+ help = " disable testing for Array API extension(s)" ,
45
44
)
46
45
47
46
48
47
def pytest_configure (config ):
49
48
config .addinivalue_line (
50
- ' markers' , ' xp_extension(ext): tests an Array API extension'
49
+ " markers" , " xp_extension(ext): tests an Array API extension"
51
50
)
52
51
# Hypothesis
53
- hypothesis_max_examples = config .getoption (' --hypothesis-max-examples' )
54
- disable_deadline = config .getoption (' --hypothesis-disable-deadline' )
52
+ hypothesis_max_examples = config .getoption (" --hypothesis-max-examples" )
53
+ disable_deadline = config .getoption (" --hypothesis-disable-deadline" )
55
54
profile_settings = {}
56
55
if hypothesis_max_examples is not None :
57
- profile_settings [' max_examples' ] = int (hypothesis_max_examples )
56
+ profile_settings [" max_examples" ] = int (hypothesis_max_examples )
58
57
if disable_deadline is not None :
59
- profile_settings [' deadline' ] = None
58
+ profile_settings [" deadline" ] = None
60
59
if profile_settings :
61
- settings .register_profile (' xp_override' , ** profile_settings )
62
- settings .load_profile (' xp_override' )
60
+ settings .register_profile (" xp_override" , ** profile_settings )
61
+ settings .load_profile (" xp_override" )
63
62
else :
64
- settings .load_profile (' xp_default' )
63
+ settings .load_profile (" xp_default" )
65
64
66
65
67
66
@lru_cache
@@ -73,35 +72,35 @@ def xp_has_ext(ext: str) -> bool:
73
72
74
73
75
74
xfail_ids = []
76
- xfails_path = Path (__file__ ).parent / ' xfails.txt'
75
+ xfails_path = Path (__file__ ).parent / " xfails.txt"
77
76
if xfails_path .exists ():
78
77
with open (xfails_path ) as f :
79
78
for line in f :
80
- if line .startswith (' array_api_tests' ):
81
- id_ = line .strip (' \n ' )
79
+ if line .startswith (" array_api_tests" ):
80
+ id_ = line .strip (" \n " )
82
81
xfail_ids .append (id_ )
83
82
84
83
85
84
def pytest_collection_modifyitems (config , items ):
86
- enabled_exts = config .getoption (' --enable-extension' )
87
- disabled_exts = config .getoption (' --disable-extension' )
85
+ enabled_exts = config .getoption (" --enable-extension" )
86
+ disabled_exts = config .getoption (" --disable-extension" )
88
87
for ext in enabled_exts :
89
88
if ext in disabled_exts :
90
- raise ValueError (f' { ext = } both enabled and disabled' )
89
+ raise ValueError (f" { ext = } both enabled and disabled" )
91
90
for item in items :
92
91
# enable/disable extensions
93
92
try :
94
- ext_mark = next (m for m in item .iter_markers () if m .name == ' xp_extension' )
93
+ ext_mark = next (m for m in item .iter_markers () if m .name == " xp_extension" )
95
94
ext = ext_mark .args [0 ]
96
95
if ext in disabled_exts :
97
96
item .add_marker (
98
- mark .skip (reason = f' { ext } disabled in --disable-extensions' )
97
+ mark .skip (reason = f" { ext } disabled in --disable-extensions" )
99
98
)
100
- elif not ext in enabled_exts and not xp_has_ext (ext ):
101
- item .add_marker (mark .skip (reason = f' { ext } not found in array module' ))
99
+ elif ext not in enabled_exts and not xp_has_ext (ext ):
100
+ item .add_marker (mark .skip (reason = f" { ext } not found in array module" ))
102
101
except StopIteration :
103
102
pass
104
103
# workflow xfail_ids
105
104
for id_ in xfail_ids :
106
105
if item .nodeid .startswith (id_ ):
107
- item .add_marker (mark .xfail (reason = ' xfails.txt' ))
106
+ item .add_marker (mark .xfail (reason = " xfails.txt" ))
0 commit comments