Skip to content

Commit 6e32426

Browse files
authored
Fix none config file issue 3611 (#3613)
1 parent 0805c83 commit 6e32426

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

docs/changelog/3611.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix ``None`` appearing as the config filename in error output
2+
when the user's default config file is corrupt. - by :user:`kurtmckee`

src/tox/config/cli/ini.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __init__(self) -> None:
3939
if self.has_tox_section:
4040
self.ini = IniLoader(CORE, parser, overrides=[], core_section=CORE)
4141
except Exception as exception: # noqa: BLE001
42-
logging.error("failed to read config file %s because %r", config_file, exception) # noqa: TRY400
42+
logging.error("failed to read config file %s because %r", self.config_file, exception) # noqa: TRY400
4343
self.has_config_file = None
4444

4545
def get(self, key: str, of_type: type[Any]) -> Any:

tests/config/cli/test_cli_ini.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,21 @@ def test_ini_help(exhaustive_ini: Path, capfd: CaptureFixture) -> None:
247247
res = out.splitlines()[-1]
248248
msg = f"config file {str(exhaustive_ini)!r} active (changed via env var TOX_USER_CONFIG_FILE)"
249249
assert res == msg
250+
251+
252+
def test_ini_loader_corrupt_default_config_file(
253+
mocker: MockerFixture,
254+
tmp_path: Path,
255+
caplog: LogCaptureFixture,
256+
) -> None:
257+
# Setup: Create a corrupt DEFAULT_CONFIG_FILE and point to it.
258+
config_file = tmp_path / "config.ini"
259+
config_file.write_text("[tox\n")
260+
mocker.patch("tox.config.cli.ini.DEFAULT_CONFIG_FILE", config_file)
261+
262+
# Act
263+
IniConfig()
264+
265+
# Verify
266+
assert "failed to read config file None" not in caplog.messages[0]
267+
assert f"failed to read config file {config_file}" in caplog.messages[0]

0 commit comments

Comments
 (0)