11from functools import lru_cache
22from pathlib import Path
33
4- from pytest import mark
54from hypothesis import settings
5+ from pytest import mark
66
77from array_api_tests import _array_module as xp
88from array_api_tests ._array_module import _UndefinedStub
99
10-
11- settings .register_profile ('xp_default' , deadline = 800 )
10+ settings .register_profile ("xp_default" , deadline = 800 )
1211
1312
1413def pytest_addoption (parser ):
1514 # Hypothesis max examples
1615 # See https://github.com/HypothesisWorks/hypothesis/issues/2434
1716 parser .addoption (
18- ' --hypothesis-max-examples' ,
19- ' --max-examples' ,
20- action = ' store' ,
17+ " --hypothesis-max-examples" ,
18+ " --max-examples" ,
19+ action = " store" ,
2120 default = None ,
22- help = ' set the Hypothesis max_examples setting' ,
21+ help = " set the Hypothesis max_examples setting" ,
2322 )
2423 # Hypothesis deadline
2524 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" ,
3029 )
3130 # enable/disable extensions
3231 parser .addoption (
33- ' --enable-extension' ,
34- metavar = ' ext' ,
35- nargs = '+' ,
32+ " --enable-extension" ,
33+ metavar = " ext" ,
34+ nargs = "+" ,
3635 default = [],
37- help = ' enable testing for Array API extension(s)' ,
36+ help = " enable testing for Array API extension(s)" ,
3837 )
3938 parser .addoption (
40- ' --disable-extension' ,
41- metavar = ' ext' ,
42- nargs = '+' ,
39+ " --disable-extension" ,
40+ metavar = " ext" ,
41+ nargs = "+" ,
4342 default = [],
44- help = ' disable testing for Array API extension(s)' ,
43+ help = " disable testing for Array API extension(s)" ,
4544 )
4645
4746
4847def pytest_configure (config ):
4948 config .addinivalue_line (
50- ' markers' , ' xp_extension(ext): tests an Array API extension'
49+ " markers" , " xp_extension(ext): tests an Array API extension"
5150 )
5251 # 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" )
5554 profile_settings = {}
5655 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 )
5857 if disable_deadline is not None :
59- profile_settings [' deadline' ] = None
58+ profile_settings [" deadline" ] = None
6059 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" )
6362 else :
64- settings .load_profile (' xp_default' )
63+ settings .load_profile (" xp_default" )
6564
6665
6766@lru_cache
@@ -73,35 +72,35 @@ def xp_has_ext(ext: str) -> bool:
7372
7473
7574xfail_ids = []
76- xfails_path = Path (__file__ ).parent / ' xfails.txt'
75+ xfails_path = Path (__file__ ).parent / " xfails.txt"
7776if xfails_path .exists ():
7877 with open (xfails_path ) as f :
7978 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 " )
8281 xfail_ids .append (id_ )
8382
8483
8584def 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" )
8887 for ext in enabled_exts :
8988 if ext in disabled_exts :
90- raise ValueError (f' { ext = } both enabled and disabled' )
89+ raise ValueError (f" { ext = } both enabled and disabled" )
9190 for item in items :
9291 # enable/disable extensions
9392 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" )
9594 ext = ext_mark .args [0 ]
9695 if ext in disabled_exts :
9796 item .add_marker (
98- mark .skip (reason = f' { ext } disabled in --disable-extensions' )
97+ mark .skip (reason = f" { ext } disabled in --disable-extensions" )
9998 )
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" ))
102101 except StopIteration :
103102 pass
104103 # workflow xfail_ids
105104 for id_ in xfail_ids :
106105 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