1111from collections .abc import Iterable
1212from collections .abc import Iterator
1313from collections .abc import Mapping
14+ from collections .abc import MutableMapping
1415from collections .abc import Sequence
1516import contextlib
1617import copy
4849from .compat import PathAwareHookProxy
4950from .exceptions import PrintHelp as PrintHelp
5051from .exceptions import UsageError as UsageError
52+ from .findpaths import ConfigDict
53+ from .findpaths import ConfigValue
5154from .findpaths import determine_setup
5255from _pytest import __version__
5356import _pytest ._code
@@ -979,6 +982,30 @@ def _iter_rewritable_modules(package_files: Iterable[str]) -> Iterator[str]:
979982 yield from _iter_rewritable_modules (new_package_files )
980983
981984
985+ class _DeprecatedInicfgProxy (MutableMapping [str , Any ]):
986+ """Compatibility proxy for the deprecated Config.inicfg."""
987+
988+ __slots__ = ("_config" ,)
989+
990+ def __init__ (self , config : Config ) -> None :
991+ self ._config = config
992+
993+ def __getitem__ (self , key : str ) -> Any :
994+ return self ._config ._inicfg [key ].value
995+
996+ def __setitem__ (self , key : str , value : Any ) -> None :
997+ self ._config ._inicfg [key ] = ConfigValue (value , origin = "override" , mode = "toml" )
998+
999+ def __delitem__ (self , key : str ) -> None :
1000+ del self ._config ._inicfg [key ]
1001+
1002+ def __iter__ (self ) -> Iterator [str ]:
1003+ return iter (self ._config ._inicfg )
1004+
1005+ def __len__ (self ) -> int :
1006+ return len (self ._config ._inicfg )
1007+
1008+
9821009@final
9831010class Config :
9841011 """Access to configuration values, pluginmanager and plugin hooks.
@@ -1089,6 +1116,7 @@ def __init__(
10891116 self .trace = self .pluginmanager .trace .root .get ("config" )
10901117 self .hook : pluggy .HookRelay = PathAwareHookProxy (self .pluginmanager .hook ) # type: ignore[assignment]
10911118 self ._inicache : dict [str , Any ] = {}
1119+ self ._inicfg : ConfigDict = {}
10921120 self ._cleanup_stack = contextlib .ExitStack ()
10931121 self .pluginmanager .register (self , "pytestconfig" )
10941122 self ._configured = False
@@ -1098,6 +1126,10 @@ def __init__(
10981126 self .args_source = Config .ArgsSource .ARGS
10991127 self .args : list [str ] = []
11001128
1129+ @property
1130+ def inicfg (self ) -> _DeprecatedInicfgProxy :
1131+ return _DeprecatedInicfgProxy (self )
1132+
11011133 @property
11021134 def rootpath (self ) -> pathlib .Path :
11031135 """The path to the :ref:`rootdir <rootdir>`.
@@ -1428,7 +1460,7 @@ def _warn_or_fail_if_strict(self, message: str) -> None:
14281460
14291461 def _get_unknown_ini_keys (self ) -> set [str ]:
14301462 known_keys = self ._parser ._inidict .keys () | self ._parser ._ini_aliases .keys ()
1431- return self .inicfg .keys () - known_keys
1463+ return self ._inicfg .keys () - known_keys
14321464
14331465 def parse (self , args : list [str ], addopts : bool = True ) -> None :
14341466 # Parse given cmdline arguments into this config object.
@@ -1459,7 +1491,7 @@ def parse(self, args: list[str], addopts: bool = True) -> None:
14591491 self ._rootpath = rootpath
14601492 self ._inipath = inipath
14611493 self ._ignored_config_files = ignored_config_files
1462- self .inicfg = inicfg
1494+ self ._inicfg = inicfg
14631495 self ._parser .extra_info ["rootdir" ] = str (self .rootpath )
14641496 self ._parser .extra_info ["inifile" ] = str (self .inipath )
14651497
@@ -1636,14 +1668,14 @@ def _getini(self, name: str):
16361668 except KeyError as e :
16371669 raise ValueError (f"unknown configuration value: { name !r} " ) from e
16381670
1639- # Collect all possible values (canonical name + aliases) from inicfg .
1671+ # Collect all possible values (canonical name + aliases) from _inicfg .
16401672 # Each candidate is (ConfigValue, is_canonical).
16411673 candidates = []
1642- if canonical_name in self .inicfg :
1643- candidates .append ((self .inicfg [canonical_name ], True ))
1674+ if canonical_name in self ._inicfg :
1675+ candidates .append ((self ._inicfg [canonical_name ], True ))
16441676 for alias , target in self ._parser ._ini_aliases .items ():
1645- if target == canonical_name and alias in self .inicfg :
1646- candidates .append ((self .inicfg [alias ], False ))
1677+ if target == canonical_name and alias in self ._inicfg :
1678+ candidates .append ((self ._inicfg [alias ], False ))
16471679
16481680 if not candidates :
16491681 return default
0 commit comments