From 148d570909e9254922bcc9d348b19d9cf66a3b7d Mon Sep 17 00:00:00 2001 From: Kurt McKee Date: Thu, 18 Sep 2025 15:17:54 -0500 Subject: [PATCH 1/2] Demonstrate issue #3611 --- tests/config/cli/test_cli_ini.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/config/cli/test_cli_ini.py b/tests/config/cli/test_cli_ini.py index 3af81965e..c78957dbe 100644 --- a/tests/config/cli/test_cli_ini.py +++ b/tests/config/cli/test_cli_ini.py @@ -247,3 +247,21 @@ def test_ini_help(exhaustive_ini: Path, capfd: CaptureFixture) -> None: res = out.splitlines()[-1] msg = f"config file {str(exhaustive_ini)!r} active (changed via env var TOX_USER_CONFIG_FILE)" assert res == msg + + +def test_ini_loader_corrupt_default_config_file( + mocker: MockerFixture, + tmp_path: Path, + caplog: LogCaptureFixture, +) -> None: + # Setup: Create a corrupt DEFAULT_CONFIG_FILE and point to it. + config_file = tmp_path / "config.ini" + config_file.write_text("[tox\n") + mocker.patch("tox.config.cli.ini.DEFAULT_CONFIG_FILE", config_file) + + # Act + IniConfig() + + # Verify + assert "failed to read config file None" not in caplog.messages[0] + assert f"failed to read config file {config_file}" in caplog.messages[0] From 95162103f2cca98278b18b9730c936d63a3e4dcd Mon Sep 17 00:00:00 2001 From: Kurt McKee Date: Thu, 18 Sep 2025 15:19:09 -0500 Subject: [PATCH 2/2] Fix `failed to read config file None` when `DEFAULT_CONFIG_FILE` is corrupt Fixes #3611 --- docs/changelog/3611.bugfix.rst | 2 ++ src/tox/config/cli/ini.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 docs/changelog/3611.bugfix.rst diff --git a/docs/changelog/3611.bugfix.rst b/docs/changelog/3611.bugfix.rst new file mode 100644 index 000000000..dd0a1f72a --- /dev/null +++ b/docs/changelog/3611.bugfix.rst @@ -0,0 +1,2 @@ +Fix ``None`` appearing as the config filename in error output +when the user's default config file is corrupt. - by :user:`kurtmckee` diff --git a/src/tox/config/cli/ini.py b/src/tox/config/cli/ini.py index a4ee0efa9..82c29c5a9 100644 --- a/src/tox/config/cli/ini.py +++ b/src/tox/config/cli/ini.py @@ -39,7 +39,7 @@ def __init__(self) -> None: if self.has_tox_section: self.ini = IniLoader(CORE, parser, overrides=[], core_section=CORE) except Exception as exception: # noqa: BLE001 - logging.error("failed to read config file %s because %r", config_file, exception) # noqa: TRY400 + logging.error("failed to read config file %s because %r", self.config_file, exception) # noqa: TRY400 self.has_config_file = None def get(self, key: str, of_type: type[Any]) -> Any: