|
11 | 11 | from collections.abc import Iterable |
12 | 12 | from collections.abc import Iterator |
13 | 13 | from collections.abc import Mapping |
| 14 | +from collections.abc import MutableMapping |
14 | 15 | from collections.abc import Sequence |
15 | 16 | import contextlib |
16 | 17 | import copy |
|
47 | 48 | from .compat import PathAwareHookProxy |
48 | 49 | from .exceptions import PrintHelp as PrintHelp |
49 | 50 | from .exceptions import UsageError as UsageError |
| 51 | +from .findpaths import ConfigValue |
50 | 52 | from .findpaths import determine_setup |
51 | 53 | from _pytest import __version__ |
52 | 54 | import _pytest._code |
@@ -980,6 +982,30 @@ def _iter_rewritable_modules(package_files: Iterable[str]) -> Iterator[str]: |
980 | 982 | yield from _iter_rewritable_modules(new_package_files) |
981 | 983 |
|
982 | 984 |
|
| 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 | + |
983 | 1009 | @final |
984 | 1010 | class Config: |
985 | 1011 | """Access to configuration values, pluginmanager and plugin hooks. |
@@ -1100,6 +1126,10 @@ def __init__( |
1100 | 1126 | self.args_source = Config.ArgsSource.ARGS |
1101 | 1127 | self.args: list[str] = [] |
1102 | 1128 |
|
| 1129 | + @property |
| 1130 | + def inicfg(self) -> _DeprecatedInicfgProxy: |
| 1131 | + return _DeprecatedInicfgProxy(self) |
| 1132 | + |
1103 | 1133 | @property |
1104 | 1134 | def rootpath(self) -> pathlib.Path: |
1105 | 1135 | """The path to the :ref:`rootdir <rootdir>`. |
@@ -1376,7 +1406,7 @@ def pytest_collection(self) -> Generator[None, object, object]: |
1376 | 1406 | def _checkversion(self) -> None: |
1377 | 1407 | import pytest |
1378 | 1408 |
|
1379 | | - minver_ini_value = self.inicfg.get("minversion", None) |
| 1409 | + minver_ini_value = self._inicfg.get("minversion", None) |
1380 | 1410 | minver = minver_ini_value.value if minver_ini_value is not None else None |
1381 | 1411 | if minver: |
1382 | 1412 | # Imported lazily to improve start-up time. |
@@ -1440,7 +1470,7 @@ def _warn_or_fail_if_strict(self, message: str) -> None: |
1440 | 1470 |
|
1441 | 1471 | def _get_unknown_ini_keys(self) -> set[str]: |
1442 | 1472 | known_keys = self._parser._inidict.keys() | self._parser._ini_aliases.keys() |
1443 | | - return self.inicfg.keys() - known_keys |
| 1473 | + return self._inicfg.keys() - known_keys |
1444 | 1474 |
|
1445 | 1475 | def parse(self, args: list[str], addopts: bool = True) -> None: |
1446 | 1476 | # Parse given cmdline arguments into this config object. |
@@ -1471,7 +1501,7 @@ def parse(self, args: list[str], addopts: bool = True) -> None: |
1471 | 1501 | self._rootpath = rootpath |
1472 | 1502 | self._inipath = inipath |
1473 | 1503 | self._ignored_config_files = ignored_config_files |
1474 | | - self.inicfg = inicfg |
| 1504 | + self._inicfg = inicfg |
1475 | 1505 | self._parser.extra_info["rootdir"] = str(self.rootpath) |
1476 | 1506 | self._parser.extra_info["inifile"] = str(self.inipath) |
1477 | 1507 |
|
@@ -1648,14 +1678,14 @@ def _getini(self, name: str): |
1648 | 1678 | except KeyError as e: |
1649 | 1679 | raise ValueError(f"unknown configuration value: {name!r}") from e |
1650 | 1680 |
|
1651 | | - # Collect all possible values (canonical name + aliases) from inicfg. |
| 1681 | + # Collect all possible values (canonical name + aliases) from _inicfg. |
1652 | 1682 | # Each candidate is (ConfigValue, is_canonical). |
1653 | 1683 | candidates = [] |
1654 | | - if canonical_name in self.inicfg: |
1655 | | - candidates.append((self.inicfg[canonical_name], True)) |
| 1684 | + if canonical_name in self._inicfg: |
| 1685 | + candidates.append((self._inicfg[canonical_name], True)) |
1656 | 1686 | for alias, target in self._parser._ini_aliases.items(): |
1657 | | - if target == canonical_name and alias in self.inicfg: |
1658 | | - candidates.append((self.inicfg[alias], False)) |
| 1687 | + if target == canonical_name and alias in self._inicfg: |
| 1688 | + candidates.append((self._inicfg[alias], False)) |
1659 | 1689 |
|
1660 | 1690 | if not candidates: |
1661 | 1691 | return default |
|
0 commit comments