3838
3939
4040def pytest_addoption (parser ):
41- group = parser .getgroup ('wish ' )
41+ group = parser .getgroup ('nodev ' )
4242 group .addoption (
43- '--wish -from-stdlib' , action = 'store_true' ,
44- help = "Collects objects form the Python standard library." )
43+ '--candidates -from-stdlib' , action = 'store_true' ,
44+ help = "Collects candidates form the Python standard library." )
4545 group .addoption (
46- '--wish -from-all' , action = 'store_true' ,
47- help = "Collects objects form the Python standard library and all installed packages. "
46+ '--candidates -from-all' , action = 'store_true' ,
47+ help = "Collects candidates form the Python standard library and all installed packages. "
4848 "Disabled by default, see the docs." )
4949 group .addoption (
50- '--wish -from-specs' , default = [], nargs = '+' ,
51- help = "Collects objects from installed packages. Space separated list of `pip` specs." )
50+ '--candidates -from-specs' , default = [], nargs = '+' ,
51+ help = "Collects candidates from installed packages. Space separated list of `pip` specs." )
5252 group .addoption (
53- '--wish -from-modules' , default = [], nargs = '+' ,
54- help = "Collects objects from installed modules. Space separated list of module names." )
53+ '--candidates -from-modules' , default = [], nargs = '+' ,
54+ help = "Collects candidates from installed modules. Space separated list of module names." )
5555 group .addoption (
56- '--wish -includes' , nargs = '+' ,
56+ '--candidates -includes' , nargs = '+' ,
5757 help = "Space separated list of regexs matching full object names to include, "
58- "defaults to include all objects collected via `--wish -from-*`." )
58+ "defaults to include all objects collected via `--candidates -from-*`." )
5959 group .addoption (
60- '--wish -excludes' , default = [], nargs = '+' ,
60+ '--candidates -excludes' , default = [], nargs = '+' ,
6161 help = "Space separated list of regexs matching full object names to exclude." )
6262 group .addoption (
63- '--wish -predicate' , default = 'builtins:callable' ,
63+ '--candidates -predicate' , default = 'builtins:callable' ,
6464 help = "Full name of the predicate passed to `inspect.getmembers`, "
6565 "defaults to `builtins.callable`." )
66- group .addoption ('--wish -fail' , action = 'store_true' , help = "Show wish failures." )
66+ group .addoption ('--candidates -fail' , action = 'store_true' , help = "Show candidates failures." )
6767
6868
69- def make_wish_index (config ):
70- if config .getoption ('wish_from_all ' ) and os .environ .get ('PYTEST_NODEV_MODE' ) != 'FEARLESS' :
71- raise ValueError ("Use of --wish -from-all may be very dangerous, see the docs." )
69+ def make_candidate_index (config ):
70+ if config .getoption ('candidates_from_all ' ) and os .environ .get ('PYTEST_NODEV_MODE' ) != 'FEARLESS' :
71+ raise ValueError ("Use of --candidates -from-all may be very dangerous, see the docs." )
7272
73- if not hasattr (config , '_wish_index_items ' ):
73+ if not hasattr (config , '_candicate_index ' ):
7474 # take over collect logging
7575 collect .logger .propagate = False
7676 collect .logger .setLevel (logging .DEBUG ) # FIXME: loglevel should be configurable
@@ -82,70 +82,69 @@ def make_wish_index(config):
8282 # build the object index
8383 distributions = collections .OrderedDict ()
8484
85- if config .getoption ('wish_from_stdlib ' ) or config .getoption ('wish_from_all ' ):
85+ if config .getoption ('candidates_from_stdlib ' ) or config .getoption ('candidates_from_all ' ):
8686 distributions .update (collect .collect_stdlib_distributions ())
8787
88- if config .getoption ('wish_from_all ' ):
88+ if config .getoption ('candidates_from_all ' ):
8989 distributions .update (collect .collect_installed_distributions ())
9090
91- distributions .update (collect .collect_distributions (config .getoption ('wish_from_specs ' )))
91+ distributions .update (collect .collect_distributions (config .getoption ('candidates_from_specs ' )))
9292
93- if config .getoption ('wish_from_modules ' ):
94- distributions ['unknown distribution' ] = config .getoption ('wish_from_modules ' )
93+ if config .getoption ('candidates_from_modules ' ):
94+ distributions ['unknown distribution' ] = config .getoption ('candidates_from_modules ' )
9595
9696 top_level_modules = collect .import_distributions (distributions .items ())
9797
98- includes = config .getoption ('wish_includes ' )
98+ includes = config .getoption ('candidates_includes ' )
9999 if not includes :
100- includes = ['.' ] if config .getoption ('wish_from_all ' ) else sorted (top_level_modules )
101- excludes = config .getoption ('wish_excludes ' )
102- predicate = config .getoption ('wish_predicate ' )
100+ includes = ['.' ] if config .getoption ('candidates_from_all ' ) else sorted (top_level_modules )
101+ excludes = config .getoption ('candidates_excludes ' )
102+ predicate = config .getoption ('candidates_predicate ' )
103103
104104 # NOTE: 'copy' is needed here because indexing may unexpectedly trigger a module load
105105 modules = sys .modules .copy ()
106106 object_index = dict (
107- collect .generate_objects_from_modules (modules , includes , excludes ,
108- predicate )
107+ collect .generate_objects_from_modules (modules , includes , excludes , predicate )
109108 )
110109
111110 # store index
112- config ._wish_index_items = list (zip (* sorted (object_index .items ()))) or [(), ()]
111+ config ._candicate_index = list (zip (* sorted (object_index .items ()))) or [(), ()]
113112
114- return config ._wish_index_items
113+ return config ._candicate_index
115114
116115
117116def pytest_pycollect_makeitem (collector , name , obj ):
118- target_marker = getattr (obj , 'target ' , None )
119- if target_marker and getattr (target_marker , 'args' , []):
120- target_name = target_marker .args [0 ]
117+ candidate_marker = getattr (obj , 'candidate ' , None )
118+ if candidate_marker and getattr (candidate_marker , 'args' , []):
119+ candidate_name = candidate_marker .args [0 ]
121120
122- def wrapper (wish , monkeypatch , * args , ** kwargs ):
123- if '.' in target_name :
124- monkeypatch .setattr (target_name , wish , raising = False )
121+ def wrapper (candidate , monkeypatch , * args , ** kwargs ):
122+ if '.' in candidate_name :
123+ monkeypatch .setattr (candidate_name , candidate , raising = False )
125124 else :
126- monkeypatch .setattr (inspect .getmodule (obj ), target_name , wish , raising = False )
125+ monkeypatch .setattr (inspect .getmodule (obj ), candidate_name , candidate , raising = False )
127126 return obj (* args , ** kwargs )
128127
129128 wrapper .__dict__ = obj .__dict__
130129 return list (collector ._genfunctions (name , wrapper ))
131130
132131
133132def pytest_generate_tests (metafunc ):
134- if 'wish ' not in metafunc .fixturenames :
133+ if 'candidate ' not in metafunc .fixturenames :
135134 return
136135
137- ids , params = make_wish_index (metafunc .config )
138- metafunc .parametrize ('wish ' , params , ids = ids , scope = 'module' )
136+ ids , params = make_candidate_index (metafunc .config )
137+ metafunc .parametrize ('candidate ' , params , ids = ids , scope = 'module' )
139138
140- if not metafunc .config .getoption ('wish_fail ' ):
139+ if not metafunc .config .getoption ('candidates_fail ' ):
141140 metafunc .function = pytest .mark .xfail (metafunc .function )
142141
143142
144143def pytest_terminal_summary (terminalreporter ):
145- if not hasattr (terminalreporter .config , '_wish_index_items ' ):
144+ if not hasattr (terminalreporter .config , '_candicate_index ' ):
146145 return
147146
148- hit_state = 'passed' if terminalreporter .config .getoption ('wish_fail ' ) else 'xpassed'
147+ hit_state = 'passed' if terminalreporter .config .getoption ('candidates_fail ' ) else 'xpassed'
149148 hits = terminalreporter .getreports (hit_state )
150149 terminalreporter .write_sep ('=' , '%d hit' % len (hits ), bold = True )
151150 terminalreporter .write_line ('' )
0 commit comments