@@ -66,51 +66,49 @@ def pytest_addoption(parser):
6666
6767
6868def make_wish_index (config ):
69- if hasattr (config , '_wish_index_items' ):
70- return config ._wish_index_items
71-
7269 if config .getoption ('wish_from_all' ) and os .environ .get ('PYTEST_NODEV_MODE' ) != 'FEARLESS' :
7370 raise ValueError ("Use of --wish-from-all may be very dangerous, see the docs." )
7471
75- # take over collect logging
76- collect .logger .propagate = False
77- collect .logger .setLevel (logging .DEBUG ) # FIXME: loglevel should be configurable
78- collect .logger .addHandler (utils .EmitHandler (config ._warn ))
72+ if not hasattr (config , '_wish_index_items' ):
73+ # take over collect logging
74+ collect .logger .propagate = False
75+ collect .logger .setLevel (logging .DEBUG ) # FIXME: loglevel should be configurable
76+ collect .logger .addHandler (utils .EmitHandler (config ._warn ))
7977
80- # build the object index
81- distributions = collections . OrderedDict ( )
78+ # delegate interrupting hanging tests to pytest-timeout
79+ os . environ [ 'PYTEST_TIMEOUT' ] = os . environ . get ( 'PYTEST_TIMEOUT' , '1' )
8280
83- if config . getoption ( 'wish_from_stdlib' ) or config . getoption ( 'wish_from_all' ):
84- distributions . update ( collect . collect_stdlib_distributions () )
81+ # build the object index
82+ distributions = collections . OrderedDict ( )
8583
86- if config .getoption ('wish_from_all' ):
87- distributions .update (collect .collect_installed_distributions ())
84+ if config . getoption ( 'wish_from_stdlib' ) or config .getoption ('wish_from_all' ):
85+ distributions .update (collect .collect_stdlib_distributions ())
8886
89- distributions .update (collect .collect_distributions (config .getoption ('wish_from_specs' )))
87+ if config .getoption ('wish_from_all' ):
88+ distributions .update (collect .collect_installed_distributions ())
9089
91- if config .getoption ('wish_from_modules' ):
92- distributions ['unknown distribution' ] = config .getoption ('wish_from_modules' )
90+ distributions .update (collect .collect_distributions (config .getoption ('wish_from_specs' )))
9391
94- top_level_modules = collect .import_distributions (distributions .items ())
92+ if config .getoption ('wish_from_modules' ):
93+ distributions ['unknown distribution' ] = config .getoption ('wish_from_modules' )
9594
96- wish_includes = config .getoption ('wish_includes' )
97- if not wish_includes :
98- wish_includes = ['.' ] if config .getoption ('wish_from_all' ) else sorted (top_level_modules )
99- wish_excludes = config .getoption ('wish_excludes' )
100- wish_predicate = config .getoption ('wish_predicate' )
95+ top_level_modules = collect .import_distributions (distributions .items ())
10196
102- # NOTE: 'copy' is needed here because indexing may unexpectedly trigger a module load
103- modules = sys .modules .copy ()
104- object_index = dict (
105- collect .generate_objects_from_modules (modules , wish_includes , wish_excludes ,
106- wish_predicate )
107- )
97+ includes = config .getoption ('wish_includes' )
98+ if not includes :
99+ includes = ['.' ] if config .getoption ('wish_from_all' ) else sorted (top_level_modules )
100+ excludes = config .getoption ('wish_excludes' )
101+ predicate = config .getoption ('wish_predicate' )
108102
109- # store options
110- config ._wish_index_items = list (zip (* sorted (object_index .items ()))) or [(), ()]
103+ # NOTE: 'copy' is needed here because indexing may unexpectedly trigger a module load
104+ modules = sys .modules .copy ()
105+ object_index = dict (
106+ collect .generate_objects_from_modules (modules , includes , excludes ,
107+ predicate )
108+ )
111109
112- # delegate interrupting hanging tests to pytest-timeout
113- os . environ [ 'PYTEST_TIMEOUT' ] = os . environ . get ( 'PYTEST_TIMEOUT' , '1' )
110+ # store index
111+ config . _wish_index_items = list ( zip ( * sorted ( object_index . items ()))) or [(), ()]
114112
115113 return config ._wish_index_items
116114
0 commit comments