diff --git a/docs/changelog/3611.bugfix.rst b/docs/changelog/3611.bugfix.rst new file mode 100644 index 0000000000..dd0a1f72af --- /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 a4ee0efa92..82c29c5a96 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: diff --git a/tests/config/cli/test_cli_ini.py b/tests/config/cli/test_cli_ini.py index 3af81965ed..c78957dbea 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]