@@ -171,8 +171,9 @@ def single_process_pg():
171171
172172
173173def pytest_collection_modifyitems (items : List [pytest .Function ], config : pytest .Config ):
174+ initial_size = len (items )
174175 conditions = []
175- skipped = 0
176+ filtered , skipped = 0 , 0
176177
177178 for env_var , kwarg in (
178179 ("PL_RUN_STANDALONE_TESTS" , "standalone" ),
@@ -183,24 +184,27 @@ def pytest_collection_modifyitems(items: List[pytest.Function], config: pytest.C
183184 # this will compute the intersection of all tests selected per environment variable
184185 if os .getenv (env_var , "0" ) == "1" :
185186 conditions .append (env_var )
186- skip = pytest .mark .skip (reason = f'`{ env_var } =1` is set but the test is not a "{ kwarg } " test.' )
187- for test in items :
187+ for i , test in reversed (list (enumerate (items ))): # loop in reverse, since we are going to pop items
188188 already_skipped = any (marker .name == "skip" for marker in test .own_markers )
189189 if already_skipped :
190+ # the test was going to be skipped for a different reason, exclude it
191+ items .pop (i )
192+ skipped += 1
190193 continue
191194 # the test has `@RunIf(kwarg=True)`
192195 has_runif_with_kwarg = any (
193196 marker .name == "skipif" and marker .kwargs .get (kwarg ) for marker in test .own_markers
194197 )
195198 if not has_runif_with_kwarg :
196- test .add_marker (skip )
197- skipped += 1
198-
199- if conditions and config .option .verbose >= 0 :
200- config .get_terminal_writer ().write (
201- f"The number of tests has been filtered from { len (items )} to { len (items ) - skipped } after the filters"
202- f" { conditions } \n " ,
203- flush = True ,
199+ items .pop (i )
200+ filtered += 1
201+
202+ if config .option .verbose >= 0 and (filtered or skipped ):
203+ writer = config .get_terminal_writer ()
204+ writer .write (
205+ f"The number of tests has been filtered from { initial_size } to { initial_size - filtered } after the"
206+ f" filters { conditions } .\n { skipped } tests are marked as unconditional skips.\n In total, { len (items )} tests"
207+ f" will run.\n " ,
204208 bold = True ,
205209 purple = True , # oh yeah, branded pytest messages
206210 )
0 commit comments