@@ -1223,6 +1223,49 @@ def _validate_args(self, args: List[str], via: str) -> List[str]:
1223
1223
1224
1224
return args
1225
1225
1226
+ def _decide_args (
1227
+ self ,
1228
+ * ,
1229
+ args : List [str ],
1230
+ pyargs : List [str ],
1231
+ testpaths : List [str ],
1232
+ invocation_dir : Path ,
1233
+ rootpath : Path ,
1234
+ warn : bool ,
1235
+ ) -> Tuple [List [str ], ArgsSource ]:
1236
+ """Decide the args (initial paths/nodeids) to use given the relevant inputs.
1237
+
1238
+ :param warn: Whether can issue warnings.
1239
+ """
1240
+ if args :
1241
+ source = Config .ArgsSource .ARGS
1242
+ result = args
1243
+ else :
1244
+ if invocation_dir == rootpath :
1245
+ source = Config .ArgsSource .TESTPATHS
1246
+ if pyargs :
1247
+ result = testpaths
1248
+ else :
1249
+ result = []
1250
+ for path in testpaths :
1251
+ result .extend (sorted (glob .iglob (path , recursive = True )))
1252
+ if testpaths and not result :
1253
+ if warn :
1254
+ warning_text = (
1255
+ "No files were found in testpaths; "
1256
+ "consider removing or adjusting your testpaths configuration. "
1257
+ "Searching recursively from the current directory instead."
1258
+ )
1259
+ self .issue_config_time_warning (
1260
+ PytestConfigWarning (warning_text ), stacklevel = 3
1261
+ )
1262
+ else :
1263
+ result = []
1264
+ if not result :
1265
+ source = Config .ArgsSource .INCOVATION_DIR
1266
+ result = [str (invocation_dir )]
1267
+ return result , source
1268
+
1226
1269
def _preparse (self , args : List [str ], addopts : bool = True ) -> None :
1227
1270
if addopts :
1228
1271
env_addopts = os .environ .get ("PYTEST_ADDOPTS" , "" )
@@ -1371,34 +1414,17 @@ def parse(self, args: List[str], addopts: bool = True) -> None:
1371
1414
self .hook .pytest_cmdline_preparse (config = self , args = args )
1372
1415
self ._parser .after_preparse = True # type: ignore
1373
1416
try :
1374
- source = Config .ArgsSource .ARGS
1375
1417
args = self ._parser .parse_setoption (
1376
1418
args , self .option , namespace = self .option
1377
1419
)
1378
- if not args :
1379
- if self .invocation_params .dir == self .rootpath :
1380
- source = Config .ArgsSource .TESTPATHS
1381
- testpaths : List [str ] = self .getini ("testpaths" )
1382
- if self .known_args_namespace .pyargs :
1383
- args = testpaths
1384
- else :
1385
- args = []
1386
- for path in testpaths :
1387
- args .extend (sorted (glob .iglob (path , recursive = True )))
1388
- if testpaths and not args :
1389
- warning_text = (
1390
- "No files were found in testpaths; "
1391
- "consider removing or adjusting your testpaths configuration. "
1392
- "Searching recursively from the current directory instead."
1393
- )
1394
- self .issue_config_time_warning (
1395
- PytestConfigWarning (warning_text ), stacklevel = 3
1396
- )
1397
- if not args :
1398
- source = Config .ArgsSource .INCOVATION_DIR
1399
- args = [str (self .invocation_params .dir )]
1400
- self .args = args
1401
- self .args_source = source
1420
+ self .args , self .args_source = self ._decide_args (
1421
+ args = args ,
1422
+ pyargs = self .known_args_namespace .pyargs ,
1423
+ testpaths = self .getini ("testpaths" ),
1424
+ invocation_dir = self .invocation_params .dir ,
1425
+ rootpath = self .rootpath ,
1426
+ warn = True ,
1427
+ )
1402
1428
except PrintHelp :
1403
1429
pass
1404
1430
0 commit comments