Skip to content

Commit a32a012

Browse files
committed
config: better typing for get_config and Config.fromdictargs
1 parent 9f4bb0f commit a32a012

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/_pytest/config/__init__.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from collections.abc import Generator
1111
from collections.abc import Iterable
1212
from collections.abc import Iterator
13+
from collections.abc import Mapping
1314
from collections.abc import Sequence
1415
import contextlib
1516
import copy
@@ -290,23 +291,21 @@ def directory_arg(path: str, optname: str) -> str:
290291

291292

292293
def get_config(
293-
args: list[str] | None = None,
294+
args: Iterable[str] | None = None,
294295
plugins: Sequence[str | _PluggyPlugin] | None = None,
295296
) -> Config:
296297
# Subsequent calls to main will create a fresh instance.
297298
pluginmanager = PytestPluginManager()
298-
config = Config(
299-
pluginmanager,
300-
invocation_params=Config.InvocationParams(
301-
args=args or (),
302-
plugins=plugins,
303-
dir=pathlib.Path.cwd(),
304-
),
299+
invocation_params = Config.InvocationParams(
300+
args=args or (),
301+
plugins=plugins,
302+
dir=pathlib.Path.cwd(),
305303
)
304+
config = Config(pluginmanager, invocation_params=invocation_params)
306305

307-
if args is not None:
306+
if invocation_params.args:
308307
# Handle any "-p no:plugin" args.
309-
pluginmanager.consider_preparse(args, exclude_only=True)
308+
pluginmanager.consider_preparse(invocation_params.args, exclude_only=True)
310309

311310
for spec in default_plugins:
312311
pluginmanager.import_plugin(spec)
@@ -1202,7 +1201,7 @@ def cwd_relative_nodeid(self, nodeid: str) -> str:
12021201
return nodeid
12031202

12041203
@classmethod
1205-
def fromdictargs(cls, option_dict, args) -> Config:
1204+
def fromdictargs(cls, option_dict: Mapping[str, Any], args: list[str]) -> Config:
12061205
"""Constructor usable for subprocesses."""
12071206
config = get_config(args)
12081207
config.option.__dict__.update(option_dict)

testing/test_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,7 @@ def test_inifilename(self, tmp_path: Path) -> None:
14251425
)
14261426
with MonkeyPatch.context() as mp:
14271427
mp.chdir(cwd)
1428-
config = Config.fromdictargs(option_dict, ())
1428+
config = Config.fromdictargs(option_dict, [])
14291429
inipath = absolutepath(inifilename)
14301430

14311431
assert config.args == [str(cwd)]

0 commit comments

Comments
 (0)