Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changelog/3611.bugfix.rst
Original file line number Diff line number Diff line change
@@ -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`
2 changes: 1 addition & 1 deletion src/tox/config/cli/ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 18 additions & 0 deletions tests/config/cli/test_cli_ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]