@@ -65,64 +65,62 @@ def pytest_addoption(parser):
6565 group .addoption ('--wish-fail' , action = 'store_true' , help = "Show wish failures." )
6666
6767
68- def wish_ensuresession (config ):
69- if hasattr (config , '_wish_index_items' ):
70- return
71-
68+ def make_wish_index (config ):
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 ))
77+
78+ # delegate interrupting hanging tests to pytest-timeout
79+ os .environ ['PYTEST_TIMEOUT' ] = os .environ .get ('PYTEST_TIMEOUT' , '1' )
7980
80- # build the object index
81- distributions = collections .OrderedDict ()
81+ # build the object index
82+ distributions = collections .OrderedDict ()
8283
83- if config .getoption ('wish_from_stdlib' ) or config .getoption ('wish_from_all' ):
84- distributions .update (collect .collect_stdlib_distributions ())
84+ if config .getoption ('wish_from_stdlib' ) or config .getoption ('wish_from_all' ):
85+ distributions .update (collect .collect_stdlib_distributions ())
8586
86- if config .getoption ('wish_from_all' ):
87- distributions .update (collect .collect_installed_distributions ())
87+ if config .getoption ('wish_from_all' ):
88+ distributions .update (collect .collect_installed_distributions ())
8889
89- distributions .update (collect .collect_distributions (config .getoption ('wish_from_specs' )))
90+ distributions .update (collect .collect_distributions (config .getoption ('wish_from_specs' )))
9091
91- if config .getoption ('wish_from_modules' ):
92- distributions ['unknown distribution' ] = config .getoption ('wish_from_modules' )
92+ if config .getoption ('wish_from_modules' ):
93+ distributions ['unknown distribution' ] = config .getoption ('wish_from_modules' )
9394
94- top_level_modules = collect .import_distributions (distributions .items ())
95+ top_level_modules = collect .import_distributions (distributions .items ())
9596
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' )
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' )
101102
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- )
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+ )
108109
109- # store options
110- config ._wish_index_items = list (zip (* sorted (object_index .items ()))) or [(), ()]
110+ # store index
111+ config ._wish_index_items = list (zip (* sorted (object_index .items ()))) or [(), ()]
111112
112- # delegate interrupting hanging tests to pytest-timeout
113- os .environ ['PYTEST_TIMEOUT' ] = os .environ .get ('PYTEST_TIMEOUT' , '1' )
113+ return config ._wish_index_items
114114
115115
116116def pytest_generate_tests (metafunc ):
117117 if 'wish' not in metafunc .fixturenames :
118118 return
119119
120- config = metafunc .config
121- wish_ensuresession (config )
122-
123- ids , params = config ._wish_index_items
120+ ids , params = make_wish_index (metafunc .config )
124121 metafunc .parametrize ('wish' , params , ids = ids , scope = 'module' )
125- if not config .getoption ('wish_fail' ):
122+
123+ if not metafunc .config .getoption ('wish_fail' ):
126124 metafunc .function = pytest .mark .xfail (metafunc .function )
127125
128126
0 commit comments